Picture display question

H

Hyun Yu

On my form, I have embedded a picture (a blank image) and have coded the
following event procedure to change the picture according to the value of
two fields ("Manufacturer" and "Part_No") in the database:

-------------------------------------
Private Sub Form_Open(Cancel As Integer)
On Error Resume Next
Me.Photo.Picture = "D:\Data\Catalog Photos\" & Me.Manufacturer & "_" &
Me.Part_No & ".jpg"
End Sub
-------------------------------------

The same code is in place for Private Sub Form_Current(), Private Sub
Manufacturer_AfterUpdate(), and Private Sub Part_No_AfterUpdate().

It works fine, except that when a record is accessed that does not have the
"Manufacturer" and/or "Part_No" fields populated, in which case the image
from the previous record is displayed. I'd like to have the form display
the blank image that was originally embedded to the form when a record with
missing info on those fields is accessed.

Is there an easy way to code this?

Thanks for any help.
 
A

Adrian Jansen

Add the following ( untested code )

Private Sub Form_Open(Cancel As Integer)
dim strPic as string
On Error Resume Next
strPic = "D:\Data\Catalog Photos\" & Me.Manufacturer & "_" &
Me.Part_No & ".jpg"

if len(dir(strPic)) > 0 then 'use a directory search to verify picture is
available
Me.Photo.Picture = strPic
else
me.photo.picture = "" 'if not, set picture to null string
endif

End Sub


--
Regards,

Adrian Jansen
J & K MicroSystems
Microcomputer solutions for industrial control
 
V

Vítor Barbosa

Try this: (not tested)

-------------------------------------
Private Sub Form_Open(Cancel As Integer)
On Error Resume Next
Dim strManufacturer as String, strPart_No as String

With Me
strManufacturer = .Manufacturer
strPart_No = .Part_No

If strManufacturer <> 0 And strPart_No <> 0 then
.Photo.Picture = "D:\Data\Catalog Photos\" & strManufacturer &
"_" & strPart_No & ".jpg"
Else
.Photo.Picture = 'your blank image goes here
End If
End with

End Sub
 

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