Picture display question

  • Thread starter Thread starter Hyun Yu
  • Start date Start date
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.
 
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
 
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
 
Back
Top