Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding a different image to each record on a form 1

Status
Not open for further replies.

Nelz

Programmer
Sep 27, 2001
50
US
I got this code from this site which I got to work. The only problem is that if no image exists that corresponds to the naming in the code...it throws an error. Anyone have any ideas on what I need to add to default it to a default image???? HELP!!! Thanks!

Here's the code: It uses the orderID + .jpg to find the image that is named 1234.jpg or whatever the orderid is.

Private Sub Form_Current()
If Forms![Orders].OrderID <> 0 Then
Me![Image20].Picture = &quot;C:\My Documents\stadri\&quot; & Forms![Orders].OrderID & &quot;.jpg&quot;
End If
End Sub
 
Need to check if the file exists or not.

Private Sub Form_Current()

Dim fs
Dim fl as string
Dim fldefault as string

fldefault = &quot;.....&quot; (the default jpg file you want to use)

Set fs = CreateObject(&quot;Scripting.FileSystemObject&quot;)

If Forms![Orders].OrderID <> 0 Then
fl = &quot;C:\My Documents\stadri\&quot; & Forms![Orders].OrderID & &quot;.jpg&quot;
If fs.FileExists (fl) Then
Me![Image20].Picture = fl
Else
Me![Image20].Picture = fldefault
End if

End if

Hope this work!


 
Thanks a million!! Worked like a charm!
 
Hello,

I have some question. If [ID] is text Field, this VBA cannot work. Any method can help me?


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top