Microsoft KB Archive/148463

= ACC: How to Display Images in a Form or in a Report Without Storing the Images in a Table =

Article ID: 148463

Article Last Modified on 1/19/2007

-

APPLIES TO


 * Microsoft Access 2.0 Standard Edition
 * Microsoft Access 95 Standard Edition
 * Microsoft Access 97 Standard Edition

-



This article was previously published under Q148463



Advanced: Requires expert coding, interoperability, and multiuser skills.



SUMMARY
This article shows you how you can display bitmap images on a form or on a report with only the path and the file name stored in the Microsoft Access table.

This article assumes that you are familiar with Visual Basic for Applications and that you are familiar with creating Microsoft Access applications by using the programming tools provided with Microsoft Access.

For more information about Visual Basic for Applications, see your version of the "Building Applications with Microsoft Access" manual.

NOTE: Visual Basic for Applications is called Access Basic in Microsoft Access version 2.0. For more information about Access Basic, see the "Building Applications" manual.



MORE INFORMATION
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.

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.</li>  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 </li>  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 </li> Open the Imageform form in Form view. Notice that the form displays the corresponding bitmap for each record.</li></ol>

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 .</li> 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 .</li>  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 </li> Open the ImageReport in Print Preview mode. Notice that the report displays the corresponding bitmap for each record.</li></ol>

Creating the Table to Store File and Path Data
 Open the sample database Nwind.mdb.</li> Create a new table that is named Imagetable and then add a text field that is named ImagePath.</li>  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: <pre class="fixed_text">     c:\windows\circles.bmp c:\windows\waves.bmp c:\windows\tiles.bmp c:\windows\bubbles.bmp </li></ol>

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.</li> 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.</li> <li> 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 </li> <li> 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 </li> <li> Set the following properties for the ImageFrame unbound object frame: <pre class="fixed_text">      Enabled: Yes<BR/> Locked: No                   </li> <li>Open the Imageform in Form view. Notice that the form displays the corresponding bitmap for each record.</li></ol>

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.

<div class="references_section">