By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,395 Members | 1,396 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,395 IT Pros & Developers. It's quick & easy.

Image errors

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

"Runtime error 2220

Cannot open file "C:\Project1\Tickets\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:
Expand|Select|Wrap|Line Numbers
  1.  Message:
  2. Res1 = InputBox("Please enter a valid Ticket ID to be viewed Message")
  3. Text1 = Res1
  4. Text1 = Format(Text1, ">")
  5. Text15 = Res1
  6. Me.Refresh
  7. If Res1 = "" Then Exit Sub
  8. strTicket1 = "C:\Project1\Tickets\2007-" & Text1 & ".jpg"
  9. strNo1 = Me.Text1
  10. Me.imgTicket.Picture = strTicket1
  11.  
  12.  
I want to be able to reintroduce the InputBox when Me.imgTicket.Picture = "(none)", anyone have any ideas on how I can acieve this, as currently if I put:

Expand|Select|Wrap|Line Numbers
  1.  If Me.imgTicket.Picture ="(none)" Goto Message
Nothing happens (apart from the 2220 error message) as it is too late to catch the error! its already happened ie

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

Hopes this makes some sense to someone.

Thanks
Aug 12 '07 #1
Share this Question
Share on Google+
4 Replies


missinglinq
Expert 2.5K+
P: 3,532
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)>
Aug 12 '07 #2

ADezii
Expert 5K+
P: 8,669
I am trying to work around a problem where I can avoid the following message:

"Runtime error 2220

Cannot open file "C:\Project1\Tickets\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:
Expand|Select|Wrap|Line Numbers
  1.  Message:
  2. Res1 = InputBox("Please enter a valid Ticket ID to be viewed Message")
  3. Text1 = Res1
  4. Text1 = Format(Text1, ">")
  5. Text15 = Res1
  6. Me.Refresh
  7. If Res1 = "" Then Exit Sub
  8. strTicket1 = "C:\Project1\Tickets\2007-" & Text1 & ".jpg"
  9. strNo1 = Me.Text1
  10. Me.imgTicket.Picture = strTicket1
  11.  
  12.  
I want to be able to reintroduce the InputBox when Me.imgTicket.Picture = "(none)", anyone have any ideas on how I can acieve this, as currently if I put:

Expand|Select|Wrap|Line Numbers
  1.  If Me.imgTicket.Picture ="(none)" Goto Message
Nothing happens (apart from the 2220 error message) as it is too late to catch the error! its already happened ie

strTicket=C:\Project1\Tickets\2007-04BP1006.jpg
if this image does not exist then
Me.imgTicket.Picture=("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:
Expand|Select|Wrap|Line Numbers
  1. Dim strPathToImage As String
  2.  
  3. strPathToImage = "C:\Test\Chair.jpg"
  4.  
  5. If Dir(strPathToImage, vbNormal) <> "" Then
  6.   Me![imgTest].Picture = strPathToImage
  7. Else
  8.   MsgBox "Path to File does not exist or File Name incorrect!", vbExclamation, "Invalid File Name"
  9. End If
Aug 12 '07 #3

P: 62
You guys are fantastic!

Many thanks.
Aug 12 '07 #4

ADezii
Expert 5K+
P: 8,669
You guys are fantastic!

Many thanks.
Always glad to help!
Aug 12 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.