Image File Errors - Trapping them with VBA

kevin.philips

Active Member
Joined
Jan 7, 2003
Messages
364
Hi,

I'm struggling on this one and hope you can help...!

I have a form that contains a ListView and an Image control. I have the image control changing its LoadPicture property depending on what has been clicked in the ListView, now this works beautifully when the file exists but generates a path not found error when it doesn't, is there an easier way other than invoking a filesystem search to see if the file is available prior to setting the LoadPicture property...?

Best Regards

kevin
 

Some videos you may like

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
75,912
Office Version
  1. 365
Platform
  1. Windows
kevin

You can use Dir to see if a file exists.
Code:
If Dir("C:\MyImage.jpg")<>"" Then
   MsgBox "File exists."
Else
   MsgBox "File doesn't exist."
End If
 

Watch MrExcel Video

Forum statistics

Threads
1,113,794
Messages
5,544,322
Members
410,603
Latest member
rseckler
Top