Add record-specific image from specific path to report

mafhobb

Registered User.
Local time
Today, 09:47
Joined
Feb 28, 2006
Messages
1,249
All right, experts:). I have been trying to figure this out for a while but keep getting stuck:confused:.

I need to add an image to a report. Each record has its own image, but they are all called the same. The path for the image file for each record is specified in the hyperlink field "File Location"

Example;

Product "X". Hyperlink is "G:\Database\Product X". File name is "a.bmp"

Product "Y". Hyperlink is "G:\Database\Product Y". File name is "a.bmp"

How do I do this?

mafhobb
 
These are my rules for images Image file = Stock / Product Record, use jpegs rather than bitmaps.

Declare a path

Code:
Private Function GetImageDir() As String
    GetImageDir = G:\Database\
End Function

Then

Code:
Function GetPicture()
Dim FullPath As String
    With CodeContextObject
        FullPath = GetImageDir & .[Image File]
        If Dir([FullPath]) <> Empty Then
            .[ImageControl].Visible = True
            .[ImageControl].Picture = FullPath
        Else
            .[ImageControl].Visible = False
        End If
    End With
End Function

This works for Access 2007 the .visible stop recursive images appearing on the report when no image is available on the next record.

Simon
 
Hello Simon,

So how do I make it so the code knows to look in the folder specified in the field "File Location" (which is different for each project)?

mafhobb
 
Personally, I would be inclined to have your images Project named however something along the lines of this would probably work:

Code:
Private Function GetImageDir() As String
With CodeContextObject
GetImageDir = "G:\Database\" & .[Product] & "\"
End With
End Function
 
Last edited:
Ok, this makes sense.

Where do I put the code?
 
On a Form (On Current) =GetImage()

On a Report

Create Report just to contain the Image - Sourced from Products

Detail Section (On Print) =GetImage()

Link Parent and Child with the Product

I use a subform as the image report is used on various reports.

Simon
 
Last edited:
Excellent recommendations Simon! If I may add...

Your field in the table for the product image should just be the filename (including extension).
Have a table to hold Configuration data:

tblDefaults
------------------------
DefaultID, AutoNumber, PK
DefItem, Text
DefValue, Text
Description, Text

Have a Defaults Configuration form for this table - one record for "ImagePath", with DefItem="ImagePath". When you need to retrieve the default path: strImagePath = DLookup("DefValue","tblDefaults","DefItem='ImagePath'").

That will save some bytes in the tables, and make the Path User-Modifiable.

Simon's example already detects if the image isn't available and sets .Visible=False if it doesn't. For Database Integrity, you could run a procedure to iterate the Products table, checking (1) if an image is referenced and (2) if it is missing.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom