Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

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


View products that this article applies to.

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.

↑ Back to the top


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.

In Microsoft Access 97 and 7.0

Creating the Table to Store File and Path Data

  1. Open the sample database Northwind.mdb.
  2. Create a new table that is named Imagetable and then add a text field that is named ImagePath.
  3. 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

  1. Use the AutoForm: Columnar Wizard to create a new form that is based on the ImageTable table.
  2. 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.
  3. 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
    						
  4. 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
    						
  5. Open the Imageform form in Form view. Notice that the form displays the corresponding bitmap for each record.

Displaying Images in a Report

  1. You can use the AutoReport Wizard to create a new report that is based on the ImageTable table. Name the report ImageReport.
  2. 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.
  3. 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 
    						
  4. 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

  1. Open the sample database Nwind.mdb.
  2. Create a new table that is named Imagetable and then add a text field that is named ImagePath.
  3. 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

  1. Use the AutoForm Wizard to create a new form that is based on the ImageTable table. Name the form Imageform.
  2. 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.
  3. 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
    						
  4. 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
    						
  5. Set the following properties for the ImageFrame unbound object frame:
           Enabled: Yes<BR/>
           Locked: No
        
    					
  6. 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.

↑ Back to the top


References

For more information about the OleTypeAllowed property, search the Help Index for OleTypeAllowed, and then OleTypeAllowed Property, or ask the Microsoft Access 97 Office Assistant.

For more information about the Sourcedoc property, search the Help Index for Sourcedoc, and then SourceDoc Property, or ask the Microsoft Access 97 Office Assistant.

↑ Back to the top


Properties

Retired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.

↑ Back to the top


Keywords: kbhowto, kbinterop, kbprogramming, KB148463

↑ Back to the top

Article Info
Article ID : 148463
Revision : 6
Created on : 1/19/2007
Published on : 1/19/2007
Exists online : False
Views : 259