Using pictures on a form and report

The following question was asked in the comp.databases.ms-access newsgroup.

I'd like to add a picture in a report's detail section where the path to the picture is from a table.

Incredibly easy.  The same code works on a form as well.  Using the Toolbox drop an image control on the reports detail section.   Note that you will have to follow the dialog and actually insert an image.  But then go to the Picture property on the Format tab in the property sheet and delete the actual file.  You will probably want to set the Size Mode from clip to zoom. And rename the control to something meaningful.

Then in the report detail section in the On Print event you want to add the following lines of code

    If <logic if file available to view> Then
        Me.PhotoImage.Picture = PhotoFilePath
    Else
        Me.PhotoImage.Picture = ""
    End If

PhotoFilePath being whatever logic you want to use to figure out the file that you want printed.

You don't want to do this logic in the Format event as Microsoft has told us, via Stephen Lebans, that using that event can lead to memory leak problems.  Or you can use BMP images.   Which is rather impractical.

The reason for extensive bloating in Access when JPG or other graphic files are permanently embedded in forms or reports is that Access converts those file formats to BMP format.   This made sense back in Access 2.0 days is viewing a JPG file was very slow as it requires lots of CPU cycles.  80386 computers running Windows 3.1 were rather slow at that.  BMP format meant that you basically read the large file directly into the graphics card memory.   In Access 2007 the Access product group have updated that logic so the BMP file format isn't created any more.

Shameless plug:  I have a number of reports in the Granite Fleet Manager which print a "primary" and a number of "secondary" photo's for each unit.   See Granite Fleet manager Main Menu a screen shot and Service Order Details (with Photo) for a sample report.

Published Sun, Nov 30 2008 15:23 by Tony

Leave a Comment

(required) 
(required) 
(optional)
(required)