Refreshing an Image Control

O

OzPete

Hi all,

Thanks to Kelvin's support, I now have the image control working 24/7 and
displays pretty little pictures of my clients.

Only problem I get now is that if I go to the next record/client, and I
don't have an image [photofile] for him/her, the previous image remains, and
I cannot work out how to clear or refresh the image control, so that no
photo shows up if no photo file exists...

The [photofile] field for the client is often therefore blank, but the
previous image remains.

Code for the form to get the image...

Private Sub Form_Current()
On Error Resume Next
Me![Image40].Picture = Application.CurrentProject.Path & "\" & [PhotoFile]
End Sub

Code for the [photofile] field after update

Private Sub PhotoFile_AfterUpdate()
On Error Resume Next
Me![Image40].Picture = Application.CurrentProject.Path & "\" & [PhotoFile]
End Sub


Any clues, gang? tia

OzPete
 
C

Chris Large

Hi

You need to trap the error if there is no picture,
something like:-

Private Sub DisplayPicture()
On Error Goto NoPicture
Me![Image40].Picture = Application.CurrentProject.Path
& "\" & [PhotoFile]

Exit_Sub:
Exit Sub

NoPicture:
Me![Image40].Picture = ""
resume Exit_Sub
End Sub


Call this from the Form_Current and PhotoFile_AfterUpdate
events.

hth

Chris
 
O

OzPete

Thanks Chris...

Now, to be really cheeky, on the same no photo situation....how do I get a
label to appear in the empty space to say "No image available" ?

cheers

OzPete
 
C

Chris Large

Hi

I'd probably just create a label on the form in the same
place as the image control and set its visible property to
false at the start of the DisplayPicture sub and to true
in the error trap.

Alternatively you could create an image with the text you
want, and replace the "" in the error trap with the path &
filename of this image.

both should work ok

hth

Chris
 
K

Kelvin

You don't need to set the visible property. Just make sure the label is
behind the image control. If there is an image, the label will be covered,
if no image, then you see the label.

Kelvin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top