Avatar of holdsworthbros
holdsworthbros
 asked on

Linking images to access database

Hello Experts,
I have what I hope is a simple problem to solve in Access 2000.

I have a database that I would like to display images in. (I recently deleted all the images out of the database becuase it was getting too big).

Each record has a record ID, and all the images I want to display are stored in C:\valuations\
Not every record has an image, but all the images follow a naming format of <record ID Number>.jpg

So record 1234 has an image 1234.jpg

Is there some way I can link the image to the record to display it on the form and in the report (one record per report).
There are two outcomes I would like...

1) To be able to set up a default path to the file for each record so I dont have to manually link each file to each record. If the image is present it will automatically load.

2) To only have the image location/path stored in the database and to have it load 'as required' for viewing and printing purposes (i.e. not stored in the database).

I am a bit of an Access know-nothing so some detail would be appreciated.
Thank-you,
Chris.
Microsoft Access

Avatar of undefined
Last Comment
holdsworthbros

8/22/2022 - Mon
cquinn

Add an image control called ImageFrame to the form, and bind a control called ImageID to the record ID (you can set it to not visible if required, then in the form's OnCurrent event add the following code

 Private Sub Form_Current()
Dim strImageName as String
On Error Resume Next
strImageName="C:\Imagefolder\" & Me.[ImageID] & ".jpg"
if Dir(strImageName)<>"" then strImageName= ""   'Clear the image if one doesn't exist

Me![ImageFrame].Picture = strImageName

 End Sub
ASKER CERTIFIED SOLUTION
rockiroads

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
cquinn

Also - you can do it in this way: (Also shows how to do it in reports)

http://support.microsoft.com/?id=148463
holdsworthbros

ASKER
Hello again,
Okay I have tried to follow rockiroads advice... (I warned you, Im not good at access!) But something has gone astray...

I have a Bound Object Frame (where I would expect the image to come up) called MyImg
(is this the image control? I dont know what an image control is?)

The record ID is displayed on the form
Ive added that code to the form.
Ive also created that module

But I get an error 'Run-time error '438', Object doesnt support this property or method.

Then the de-bugger points to this line
if Dir$(sFile) <> "" Then Me.myImg.Picture = sFile else Me.myImg.Picture = ""
Highlighting:  Me.myImg.Picture = sFile else

Clearly Ive made a motzza of the myImg image control thingy.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
rockiroads

No, u dont want a bounded object frame

Its just a image control

On the toolbox toolbar, I think its the one after the command button

rockiroads

When u add the image control, and if it prompts u for a file, then select any image
then go to the field properties for that image control

Clear the setting in "Picture"  - its the file u just selected
Ensure the "picture type" is set to "Linked"
Depending on how big the pics are, u could also set the "Clip" property to be "Stretch"
holdsworthbros

ASKER
You my friend are an absolute bloody legend.

Worked a treat.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
holdsworthbros

ASKER
Just one more thing...
Ive tried doing exactly the same thing in the report, but it didnt work.

The report doesnt like the
sFile = IMAGE_DIR & Me.ID & ".jpg"
line.

Is this more complex?
rockiroads

Where in the report code did u add it? It should more or less work

Did u place it inside

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)


End Sub


rockiroads

What u might need to do is setup a default image (can be just blank) which u set in your report

e.g.

    Dim sFile As String
   
    sFile = IMAGE_DIR & Me.ID & ".jpg"
    If Dir$(sFile) <> "" Then
        Me.myImg.Picture = sFile
    Else
        Me.myImg.Picture = IMAGE_DIR & "dummy.jpg"
    End If


Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
rockiroads

Actually scrub that. I think the visible property would suit you better
e.g.

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)

    Dim sFile As String
   
    sFile = IMAGE_DIR & Me.ID & ".jpg"
    If Dir$(sFile) <> "" Then
        Me.myImg.Picture = sFile
        Me.myImg.Visible = True
    Else
        Me.myImg.Picture = ""
        Me.myImg.Visible = False
    End If

End Sub

holdsworthbros

ASKER
Clearly not, worked when I did put it in there though.