pictures in forms

G

Guest

I'm making an inventory database and I'd like the this form to display a
picture whose name natches the ItemID primary key. For example for item 1, i
will have a picture in a folder named 1.jpg

all pictures for the inventory will be in the same folder

how can i automatically have the form display the picture of the item in
question?
the path of the folder is d:\inventory\

I was thinking something like making a bounded object =
d:\inventory\"ItemID" & .jpg

but i have no idea how to do this. Any help would be greatly appreciated

Josh
 
D

DebbieG

Josh,

Here's what I did in a database. If someone knows of a simpler way please let me know.

I put a field in my table called PicturePath as a text field, Field Size = 255.

On my form, I placed:

an Image object:
Name = ThePicture
Picture = (none)
Picture Type = Linked
Size Mode = Zoom
Picture Alignment = Center
Visible = No 'made Visible in code if there is a picture
Back Style = Transparent
Special Effect = Flat
Border Style = Transparent
a text box under the Image object:
Name = ImageNote
Visible = No 'made Visible in code if there is a no picture
Enabled = No
Locked = Yes
Tab Stop = No
the PicturePath field under the ImageNote:
Visible = No
Tab Stop = No

In a module, I have:

'***********************************************************************
Public Function DisplayImage(ctlImageControl As Control, strImagePath As Variant) As String
On Error GoTo Err_DisplayImage
Dim strResult As String
With ctlImageControl
If IsNull(strImagePath) Then
.Visible = False
strResult = "No picture specified."
Else
.Visible = True
.Picture = strImagePath
End If
End With

DisplayImage = strResult

Exit_DisplayImage:
Exit Function

Err_DisplayImage:
Select Case Err.Number
' Can't find the picture.
Case 2220
ctlImageControl.Visible = False
strResult = "Can't find the picture. "
DisplayImage = strResult
Resume Exit_DisplayImage:
' Some other error.
Case Else
MsgBox Err.Number & " " & Err.Description
strResult = "An error occurred displaying image."
Resume Exit_DisplayImage:
End Select
End Function
'***********************************************************************

Behind my form:

'***********************************************************************
Private Sub Form_Current()
If IsNull(Me.PicturePath) Then
Me.ThePicture.Visible = False
Else
On Error Resume Next
Me![ThePicture].Picture = Me![PicturePath]
Me.ThePicture.Visible = True
End If

Me!ImageNote = DisplayImage(Me!ThePicture, Me!PicturePath)

If Me.ThePicture.Visible = False Then
Me.ImageNote.Visible = True
Else
Me.ImageNote.Visible = False
End If
End Sub

'***********************************************************************

I also have a command button to add a picture (which is actually adding the path to a picture) and a command button to delete a
picture. I didn't add that in case you weren't interested in this code. If you are interested, I can give it to you.

HTH,
Debbie


| I'm making an inventory database and I'd like the this form to display a
| picture whose name natches the ItemID primary key. For example for item 1, i
| will have a picture in a folder named 1.jpg
|
| all pictures for the inventory will be in the same folder
|
| how can i automatically have the form display the picture of the item in
| question?
| the path of the folder is d:\inventory\
|
| I was thinking something like making a bounded object =
| d:\inventory\"ItemID" & .jpg
|
| but i have no idea how to do this. Any help would be greatly appreciated
|
| Josh
 

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