Pictures in a Form

  • Thread starter Thread starter Branden
  • Start date Start date
B

Branden

I am putting an equipment inventory together. For each
piece of equipment I want to show its corresponding
photo. Can you do this without a degree in VBA?
 
Hi Branden

No degree required! It's reasonably straightforward really :-)

Basically, the technique is to add an image control to your form, and load
the picture file into it in the Current event, which fires whenever you move
to a new record.

Where are you storing your photos? Do you have some kind of set location
and naming convention? You can either (a) store the file path of the image
file in a field in your equipment table, or (b) create the file path from
other information - for example, all your photos might be stored in
\Images\XXX.jpg, where XXX is the EquipmentID field value and \Images is a
subfolder from the location of your database.

Here's some example code for (b):

Private Sub Form_Current()
Dim sImagePath as String
sImagePath = CurrentProject.Path & "\Images\ & Me.EquipmentID & ".jpg"
imgPhoto.Picture = sImagePath
End Sub

You can make this fancier by taking some evasive action if no photo exists
for the given item, but you get the general idea.
 
Branden said:
I am putting an equipment inventory together. For each
piece of equipment I want to show its corresponding
photo. Can you do this without a degree in VBA?

The sample databases you can download from http://accdevel.tripod.com
illustrate three approaches to handling images in Access and the included
article discusses considerations in choosing which approach to use. All
three can be useful and appropriate in particular situations, and there are
other approaches not covered there, too.

Larry Linson
Microsoft Access MVP
 
Back
Top