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

Last reviewed: August 28, 1997
Article ID: Q148463
The information in this article applies to:
  • Microsoft Access versions 2.0, 7.0, 97

SUMMARY

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

This article describes 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 demonstrate 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. Create a new form based on the ImageTable table using the Autoform Columnar Wizard. Name the form Imageform.

  5. Open the Imageform form in Design view and add an image using the Image tool on 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 ImagePath text box's AfterUpdate property 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. Create a new form based on the ImageTable table using the AutoForm Wizard. Name the form Imageform.

  5. Open the Imageform form in Design view and add an unbound object frame 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 ImagePath text box's AfterUpdate property 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.

Keywords          : kbinterop FmsHowTo
Technology        : kbole
Version           : 2.0 7.0 97
Platform          : WINDOWS
Hardware          : x86
Issue type        : kbhowto


================================================================================


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: August 28, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.