Sometimes it is not practical to store images in a Microsoft Access table.
If you have a large number of images, or if each of your image files is
large, the size of the Microsoft Access database file can rapidly increase.
The following examples show you how to display Windows bitmap images
on a Microsoft Access form and on a report without storing the images in a Microsoft
Access table.
In Microsoft Access 97 and 7.0
Creating the Table to Store File and Path Data
- Open the sample database Northwind.mdb.
- Create a new table that is named Imagetable and then add a text field that is named ImagePath.
- Open the Imagetable table in Datasheet view and then add the path and the name of a bitmap file to each record. The following examples show how the records might look:
c:\windows\circles.bmp
c:\windows\waves.bmp
c:\windows\tiles.bmp
c:\windows\bubbles.bmp
Displaying Images in a Form
- Use the AutoForm: Columnar Wizard to create a new form that is based on the ImageTable table.
- Open the Imageform form in Design view and then add an image control to the form by using the Image tool in the toolbox. You are prompted to select an image to insert. Select any image available on your computer. Name the control ImageFrame.
- Set the OnCurrent property of the Imageform form to the following event procedure:
Private Sub Form_Current()
On Error Resume Next
Me![ImageFrame].Picture = Me![ImagePath]
End Sub
- Set the AfterUpdate property of the ImagePath text box to the following event procedure:
Private Sub ImagePath_AfterUpdate()
On Error Resume Next
Me![ImageFrame].Picture = Me![ImagePath]
End Sub
- Open the Imageform form in Form view. Notice that the form displays the corresponding bitmap for each record.
Displaying Images in a Report
- You can use the AutoReport Wizard to create a new report that is based on the ImageTable table. Name the report ImageReport.
- Open ImageReport in Design view and then add an image control to the report by using the Image tool in the toolbox. You are prompted to select an image to insert. Select any image that is available on your computer. Name the control ImageFrame.
- Set the Format Event of the "Details" section of the report to the following Event Procedure:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Me![Imageframe].picture = me![Imagepath]
End Sub
- Open the ImageReport in Print Preview mode. Notice that the report displays the corresponding bitmap for each record.
In Microsoft Access 2.0
Creating the Table to Store File and Path Data
- Open the sample database Nwind.mdb.
- Create a new table that is named Imagetable and then add a text field that is named ImagePath.
- Open the Imagetable table in Datasheet view and then add the path and the name of a bitmap file to each record. The following examples show how the records might look:
c:\windows\circles.bmp
c:\windows\waves.bmp
c:\windows\tiles.bmp
c:\windows\bubbles.bmp
Displaying the Images in a Form
- Use the AutoForm Wizard to create a new form that is based on the ImageTable table. Name the form Imageform.
- Open the Imageform form in Design view and then add an unbound object frame by using the Unbound Object Frame tool in the toolbox. Name the control ImageFrame.
- Set the OnCurrent property of the Imageform form to the following event procedure:
Private Sub Form_Current()
On Error Resume Next
If Not IsNull(Me![ImagePath]) Then
Me![ImageFrame].OLETypeAllowed = 1
Me![ImageFrame].SourceDoc = Me![Imagepath]
Me![ImageFrame].Action = 0
End If
End Sub
- Set the AfterUpdate property of the ImagePath text box to the following Event Procedure:
Sub ImagePath_AfterUpdate ()
On Error Resume Next
Me![ImageFrame].OLETypeAllowed = 1
Me![ImageFrame].SourceDoc = Me![Imagepath]
Me![ImageFrame].Action = 0
End Sub
- Set the following properties for the ImageFrame unbound object frame:
Enabled: Yes<BR/>
Locked: No
- Open the Imageform in Form view. Notice that the form displays the
corresponding bitmap for each record.
NOTE: In Microsoft Access 97 and version 7.0, the form does not display any image if a not valid path or a not valid file name is added to the ImageTable table. However, error trapping can be implemented to an additional degree to make sure a valid path and a valid file name are entered. In Microsoft Access 2.0, the form ignores the error and then displays the most recent bitmap on the form.