Coding to Display Images on a Form

D

dwalsh77

I currently have a table that stores Image Paths of an item (not the images
themselves) and use a Image control on a Form to display the image. Using
some very helpful examples on image display, I used the following code to
determine the location of the DB, the image paths, and how to display the
images in the control.

i.e.,
Option Compare Database
Option Explicit
Dim filename As String, pathname As String
Dim db As DAO.Database

Private Sub Form_Activate()
'find the path of the current database
'which is where the jpegs are stored
Set db = CurrentDb
filename = db.Name
pathname = Mid(filename, 1, Len(filename) - Len(Dir(filename)))
End Sub

Private Sub Form_Current()
On Error GoTo Err_cmdClose_Click

'set the picture path
Me.ImgFrame.Picture = pathname & Me.PicturePath

Exit_cmdClose_Click:
Exit Sub

Err_cmdClose_Click:
If Err.Number = 2220 Then 'can't find the file
Resume Next
Else
MsgBox Err.Description
Resume Exit_cmdClose_Click
End If
End Sub

This worked perfectly. Now here is my problem. On the same form, I have a
Subform which I would like to display additional images for whatever item has
been selected on the main form. I am able to display the Image Path and any
additional information pertaining to the main item selected, but I cannot
display the images in a Image control.

I was thinking of doing the same coding but this time on the Subform coding
section, and not the main form.

i.e.,
Option Compare Database
Option Explicit
Dim filename As String, pathname As String
Dim db As DAO.Database

Private Sub Form_Activate()
'find the path of the current database
'which is where the jpegs are stored
Set db = CurrentDb
filename = db.Name
pathname = Mid(filename, 1, Len(filename) - Len(Dir(filename)))
End Sub

Private Sub Form_Current()
On Error GoTo Err_cmdClose_Click

'set the picture path
Me.ImgFrame2.Picture = pathname & Me.AdditionalPicturePath

Exit_cmdClose_Click:
Exit Sub

Err_cmdClose_Click:
If Err.Number = 2220 Then 'can't find the file
Resume Next
Else
MsgBox Err.Description
Resume Exit_cmdClose_Click
End If
End Sub

Any ideas on how to display those additional images on the Subform?
 

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