ACC2000: How to Display Image in Form Without Storing It in Table
ID: Q210100
|
The information in this article applies to:
Advanced: Requires expert coding, interoperability, and multiuser skills.
This article applies to a Microsoft Access database (.mdb) and a Microsoft Access project (.adp).
SUMMARY
This article shows you how you can display images on a form with only the
path and file name stored in the Microsoft Access table.
Microsoft provides programming examples for illustration only, without warranty
either expressed or implied, including, but not limited to, the implied warranties of
merchantability and/or fitness for a particular purpose. This article assumes that you
are familiar with the programming language being demonstrated and the tools used to
create and debug procedures. Microsoft support professionals can help explain the functionality
of a particular procedure, but they will not modify these examples to provide added
functionality or construct procedures to meet your specific needs. If you have limited
programming experience, you may want to contact a Microsoft Certified Solution Provider
or the Microsoft fee-based consulting line at (800) 936-5200. For more information about
Microsoft Certified Solution Providers, please see the following page on the World Wide Web:
http://www.microsoft.com/mcsp/
For more information about the support options available from Microsoft, please see the
following page on the World Wide Web:
http://www.microsoft.com/support/supportnet/overview/overview.asp
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 example show you how to display Windows bitmap images on an Access form without storing the images in an Access table. Although this example use bitmap images (.bmp), other image types will also work, for example, .jpg, .pcx, and .gif.
- Open the sample Access database file Northwind.mdb or the sample Access Project file NorthwindCS.adp.
- Create the following table in either Northwind.mdb or NorthwindCS.adp.
In Northwind.mdb:
Table: ImageTable
----------------------------
Field Name: ImageID
Data Type: Auto
Indexed: Yes (No Duplicates)
Field Name: ImagePath
Data Type: Text
Table Properties: ImageTable
----------------------------
PrimaryKey: ImageID
In NorthwindCS.adp:
Table: ImageTable
----------------------
Column Name: ImageID
Datatype: int
Allow Nulls: Unchecked
Identity: Checked
Column Name: ImagePath
Datatype: varchar
Table Properties: ImageTable
-------------------------------
Primary Key Constraint: ImageID
- 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
- Create the following new form based on the ImageTable table:
Form: Test1
-------------------------
Caption: TestForm
ControlSource: ImageTable
Image Control
---------------------------------
Name: ImageFrame
Caption: My Image
Picture: "C:\Windows\Circles.bmp"
Text box
----------------------
Name: txtImageID
ControlSource: ImageID
Note that the Picture property of the Image control has been set to the pathname for the first image; the Image control must have a valid Picture property in Design view.
- 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
- 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
- Open the Imageform form in Form view. Note that the form displays the
corresponding bitmap for each record.
REFERENCES
For more information about setting event properties, click Microsoft
Access Help on the Help menu, type "event" in the Office Assistant or the Answer Wizard, and then click
Search to view "Events: Making your database objects work together."
For more information about the OleTypeAllowed, click Microsoft Access Help on the
Help menu, type OleTypeAllowed in the Office Assistant or
the Answer Wizard, and then click Search to view the topic.
For more information about the SourceDoc property, click Microsoft Access Help on the
Help menu, type SourceDoc in the Office Assistant or
the Answer Wizard, and then click Search to view the topic.
Additional query words:
Keywords : kbinterop kbole kbdta AccCon FmsHowto KbVBA
Version : WINDOWS:2000
Platform : WINDOWS
Issue type : kbhowto