Image errors

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • boliches
    New Member
    • Feb 2007
    • 62

    #1

    Image errors

    I am trying to work around a problem where I can avoid the following message:

    "Runtime error 2220

    Cannot open file "C:\Project1\Ti ckets\2007-04BP1006.jpg" etc.

    This occurs when I try to load a file that does not exist, the rest of the script seems to work fine. I have used error traps but this one escapes. my code for this section is:
    [CODE=vb] Message:
    Res1 = InputBox("Pleas e enter a valid Ticket ID to be viewed Message")
    Text1 = Res1
    Text1 = Format(Text1, ">")
    Text15 = Res1
    Me.Refresh
    If Res1 = "" Then Exit Sub
    strTicket1 = "C:\Project1\Ti ckets\2007-" & Text1 & ".jpg"
    strNo1 = Me.Text1
    Me.imgTicket.Pi cture = strTicket1

    [/CODE] I want to be able to reintroduce the InputBox when Me.imgTicket.Pi cture = "(none)", anyone have any ideas on how I can acieve this, as currently if I put:

    [CODE=vb] If Me.imgTicket.Pi cture ="(none)" Goto Message[/CODE]

    Nothing happens (apart from the 2220 error message) as it is too late to catch the error! its already happened ie

    strTicket=C:\Pr oject1\Tickets\ 2007-04BP1006.jpg
    if this image does not exist then
    Me.imgTicket.Pi cture=("none")

    Hopes this makes some sense to someone.

    Thanks
  • missinglinq
    Recognized Expert Specialist
    • Nov 2006
    • 3533

    #2
    You have inadvertently posted your question in the Articles section rather than in the Forum section of our site, so I have moved it across to te Forum for you.

    While single lines of code don't necessarily require the use of Code Tags, all code posted consisting of 2 or more lines does.

    This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

    When posting VBA code, please tag it specifically as VBA code. It's really simple; after hi-liting the code and clicking on the # icon, go to the opening code tag and change code to code=vbl . Just like that, with no spaces between code = or vb.

    Doing this allows the editor to color code various components in theVBA code , making it much easier for everyone to read! I've gone ahead and re-tagged this one for you.

    Thank you!

    Linq ;0)>

    Comment

    • ADezii
      Recognized Expert Expert
      • Apr 2006
      • 8834

      #3
      Originally posted by boliches
      I am trying to work around a problem where I can avoid the following message:

      "Runtime error 2220

      Cannot open file "C:\Project1\Ti ckets\2007-04BP1006.jpg" etc.

      This occurs when I try to load a file that does not exist, the rest of the script seems to work fine. I have used error traps but this one escapes. my code for this section is:
      [CODE=vb] Message:
      Res1 = InputBox("Pleas e enter a valid Ticket ID to be viewed Message")
      Text1 = Res1
      Text1 = Format(Text1, ">")
      Text15 = Res1
      Me.Refresh
      If Res1 = "" Then Exit Sub
      strTicket1 = "C:\Project1\Ti ckets\2007-" & Text1 & ".jpg"
      strNo1 = Me.Text1
      Me.imgTicket.Pi cture = strTicket1

      [/CODE] I want to be able to reintroduce the InputBox when Me.imgTicket.Pi cture = "(none)", anyone have any ideas on how I can acieve this, as currently if I put:

      [CODE=vb] If Me.imgTicket.Pi cture ="(none)" Goto Message[/CODE]

      Nothing happens (apart from the 2220 error message) as it is too late to catch the error! its already happened ie

      strTicket=C:\Pr oject1\Tickets\ 2007-04BP1006.jpg
      if this image does not exist then
      Me.imgTicket.Pi cture=("none")

      Hopes this makes some sense to someone.

      Thanks
      Before loading a File into an Image Control, always make sure the Path is correct and the File does exist, as in:
      [CODE=vb]Dim strPathToImage As String

      strPathToImage = "C:\Test\Chair. jpg"

      If Dir(strPathToIm age, vbNormal) <> "" Then
      Me![imgTest].Picture = strPathToImage
      Else
      MsgBox "Path to File does not exist or File Name incorrect!", vbExclamation, "Invalid File Name"
      End If[/CODE]

      Comment

      • boliches
        New Member
        • Feb 2007
        • 62

        #4
        You guys are fantastic!

        Many thanks.

        Comment

        • ADezii
          Recognized Expert Expert
          • Apr 2006
          • 8834

          #5
          Originally posted by boliches
          You guys are fantastic!

          Many thanks.
          Always glad to help!

          Comment

          Working...