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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

If no match image file found fo record, last image displays

Status
Not open for further replies.

Debbie37

Technical User
Feb 23, 2002
28
US
I used the below example and it works, but if a record does not have a picture on file to load, the last picture remains in the image control. How can I make this control not visible if there is no image file matching the unique ID requested? It only changes when there is a different picture to load.

Private Sub Form_Current()
If Me![ID]<> 0 then
Me!Image14.Picture=&quot;C:\MyPhotos\Pics\&quot;&Me![ID]&.jpg&quot;
End if
End sub

To be clearer, I guess, is that all my records have an ID, just some do not have image files. So when you cycle through the records correct images dispay for the ID, however if the record has no image file, it continues to show the last image. I would rather the control be come invisible. Any ideas will be most appreciated!
 
Yeah, if you are using the control I am thinking of, look for a function (ie. method) of that control that repaints the object. If memory serves, its a multi-step process of setting the path to the image and repainting the control using that control's operation.

Hope that helps.

Gary
gwinn7
A+, Network+
 
In the case of &quot;no image&quot;, then you could use the DIR command. If the DIR function returns an empty string, then the file does not exist. Using an IF or IIF condition, you can make the control invisible. Something like this...

Private Sub Form_Current()

If Not Me.NewRecord then
Me.Image14.Visible = _
IIF(DIR(strPathToPhoto & Me.ID & &quot;.jpg&quot;) =&quot;&quot;,False,True)

If Me.Image14.Visible then
Me!Image14.Picture=&quot;C:\MyPhotos\Pics\&quot;&Me![ID]&.jpg&quot;
Me!Image14.<some repaint operation?>
End if

End if
End sub

The above code first checks to make sure you aren't creating a new record (ie. no ID). Then, it checks to see if the file exists. If it exists, then it sets the visibility of the control properly. After that, it assigns the new picture based on the visibility of the control.

Gary
gwinn7
A+, Network+
 
Perfect! You were right, I needed to repaint the object. I added the folowing:

Private Sub Form_Current()

If Not Me.NewRecord then
Me.Image14.Visible = _
IIF(DIR(strPathToPhoto & Me.ID & &quot;.jpg&quot;) =&quot;&quot;,False,True)

If Me.Image14.Visible then
Me!Image14.Picture=&quot;C:\MyPhotos\Pics\&quot;&Me![ID]&.jpg&quot;
DoCmd.RepaintObject acForm, &quot;PhysicianDemo&quot;
End if
End if
End sub

Thanks tons! Have a super-fantastic day!!
 
Perfect! You were right, I needed to repaint the object. I added the following:

Private Sub Form_Current()

If Not Me.NewRecord then
Me.Image14.Visible = _
IIF(DIR(strPathToPhoto & Me.ID & &quot;.jpg&quot;) =&quot;&quot;,False,True)

If Me.Image14.Visible then
Me!Image14.Picture=&quot;C:\MyPhotos\Pics\&quot;&Me![ID]&.jpg&quot;
DoCmd.RepaintObject acForm, &quot;PhysicianDemo&quot;
End if
End if
End sub

Thanks tons! Have a super-fantastic day!!
 
Repainting the entire form is not what I had in mind, but if it works for you, cool.

Glad I could help.

Gary
gwinn7
A+, Network+

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top