ACC: How to Display Image in Form Without Storing It in Table

ID: Q148463

The information in this article applies to:

SUMMARY

Advanced: Requires expert coding, interoperability, and multi-user skills.

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

This article assumes that you are familiar with Visual Basic for Applications and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information about Visual Basic for Applications, please refer to 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, please refer to 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 without storing the images in a Microsoft Access table.

In Microsoft Access 97 and 7.0

1. Open the sample database Northwind.mdb.

2. Create an new table named Imagetable and add a text field named

   ImagePath.

3. Open the Imagetable table in Datasheet view and add the path and 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

4. Use the AutoForm: Columnar Wizard to create a new form based on the
   ImageTable table.

5. Open the Imageform form in Design view and add an image control to the
   form by using the Image tool in the toolbox. You will be prompted to
   select an image to insert. Select any image available on your computer.
   Name the control ImageFrame.

6. Set the Imageform form's OnCurrent property to the following event
   procedure:

      Private Sub Form_Current()
         On Error Resume Next
         Me![ImageFrame].Picture = Me![ImagePath]
      End Sub

7. Set the AfterUpdate property of the ImagePath text box to the following
   event procedure:

      Private Sub Form_AfterUpdate()
         On Error Resume Next
         Me![ImageFrame].Picture = Me![ImagePath]
      End Sub

8. Open the Imageform form in Form view. Note that the form displays the
   corresponding bitmap for each record.

In Microsoft Access 2.0

1. Open the sample database NWIND.MDB.

2. Create an new table named Imagetable and add a text field named

   ImagePath.

3. Open the Imagetable table in Datasheet view and add the path and 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

4. Use the AutoForm Wizard to create a new form based on the ImageTable
   table. Name the form Imageform.

5. Open the Imageform form in Design view and add an unbound object frame
   by using the Unbound Object Frame tool on the toolbox. Name the control
   ImageFrame.

6. Set the Imageform form's OnCurrent property 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

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

8. Set the following properties for the ImageFrame unbound object frame:

       Enabled: Yes
       Locked: No

9. Open the Imageform in Form view. Note that the form displays the
   corresponding bitmap for each record.

NOTE: In Microsoft Access 97 and 7.0, the form will not display any image if an invalid path or file name is added to the ImageTable table. However, error trapping can be implemented to a further degree to ensure a valid path and file name are entered. In Microsoft Access 2.0, the form will just ignore the error and display the most recent bitmap on the form.

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.

Additional query qords:

Keywords          : kbinterop FmsHowto 
Version           : 2.0 7.0 97
Platform          : WINDOWS
Hardware          : x86
Issue type        : kbhowto

Last Reviewed: November 21, 1998