View Picture on form help

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi

I have a table (Employees) with one of the fields being called photo. It is a text field and contains the name of the image associated with the record. The image for employee 1 is named empid1.bmp

All images are stored in exactly the same folder as the database.

I created a form using the wizard and only using the above mentioned table. As an absolute newbie to Access, how can I view the image of each employee as I scan through the records. I know I have to add an image object but I don't know which one or how to link it. I am using Access 2002 if that makes a difference.

Like I said, I am very new to access so as much info on getting past this problem would be greatly appreciated.

Thanks in advance
 
Fortunately, this is fairly simple.

You will need to add an image control to the form, & add a little code to
the Form_Current event in order to display the image:

Add an image control to the form & name it imgMain.
Add a text box control to the form & set its ControlSource to your field
which contains the photographs filename. Name this txtPhoto

Next, select the form properties (double-click on the top-left corner of the
form when in design view).
Goto the Event Tab & under 'On Current' Select [Event Procedure]
Next click on the '...' button to the right of the text.
Add the following code:

Private Sub Form_Current()
Dim strPath As String
strPath = CurrentProject.Path & "\" & Me.txtPhoto
Me.imgMain.Picture = strPath
End Sub


N.B. This relies on the text field being complete, & ending in a valid
extension (e.g. .jpg, .bmp). It will also error if the image is not found...




--
Cheers,


James Goodman MCSE, MCDBA
http://www.angelfire.com/sports/f1pictures
 
Back
Top