Loading and Displaying an Image (Access 95 and 97)

Take the following steps to start a project and to add some code that positions, scales, and displays an image on a form:

1.  Start Microsoft Access 95 or 97.

2. Select Blank Database, and click OK; then select a database name and click Create.

3. In the Database window, select the Forms tab, and click the New button.

4. In the New Form window, select Design View and click OK.

5. Click and drag the form's detail area to make it large enough to hold an image and some command buttons.

6. On the Insert pull-down menu, use the Custom Control option (in Access 97, the ActiveX Control option) to select the Lead Control (12).

7. Click the OK button. The lead control appears on the form.

8. Size and position the control as you want it to appear at run time, and change the name of the control to Lead1.

9. image\btncmd.gif Add a command button to your form and name it as follows. (Cancel the Command Button Wizard when it appears.)

Name

Caption

LoadLead

Load Image

10. Click the Code Window icon on the toolbar.

image\btncode.gif For Access 95.

image\btncode2.gif For Access 97.

11. Select the Load procedure for the form, and add the following initialization code. In online help, you can select the block of code with the mouse, then press Ctrl-C to copy it.

Private Sub Form_Load()

  'Set defaults for displaying the image.
  'These are all persistent properties that can be set in the properties box.
  Lead1.Appearance = APPEARANCE_FLAT
  Lead1.BorderStyle = 1
  Lead1.BackColor = RGB(255, 255, 125)
  Lead1.PaintDither = PAINTDITHER_DIFFUSION
  Lead1.PaintPalette = PAINTPALETTE_AUTO
  Lead1.AutoRepaint = True
  Lead1.AutoSize = False
  Lead1.AutoSetRects = True
  Lead1.PaintSizeMode = PAINTSIZEMODE_FIT
End Sub

12. Code the LoadLead button's click procedure as follows:

Private Sub LoadLead_Click()
    Lead1.Load "c:\lead\images\image1.cmp", 0, 0, 1
End Sub

13. image\btncmpl.gif Click the compile button on the toolbar; then close the code window.

14. Close the form designer, saving the changes.

15. With Form1 selected in the Database window, click the Open button to test the form.

Note: For 256-color mode, you can improve the image quality as explained in Palette Usage in Microsoft Access.