Linking to image based on another field

MyWebdots

Registered User.
Local time
Today, 12:05
Joined
Nov 8, 2010
Messages
11
Hi there,
I have roamed around a few forums looking for the right answers using every possible search I can think of. But alas - I still can't work out - what I thought was a simple issue. :o Can someone here help me please?

I have a simple DB with one table and one form. (MS Access 2007)
The fields are text only.
One of those fields is a simple text reference that is matched to an image.
EG: the field contains 'ACA1' and there is an associated image called ACA1.jpg

The images are stored in relative folder to the DB - \images\aca1.jpg

For every record I want the form to display the corresponding image for that record. Every record has a different reference I have typed in. I can easily change the reference text to read aca1.jpg as text if that helps.

Attached is a simple screengrab. Does this make sense?
Thank you so much in advance...

Katie
 

Attachments

  • DB_screengrab.jpg
    DB_screengrab.jpg
    51.1 KB · Views: 114
Here is a simple example:

Based on the information you have given I would use three parts to your image handling although I would be included to reference your image Acadia rather than aca1. I realise that once you get beyond Genus this might not be possible but it is useful to images naming conventions that are recognisable. Anyway:


1) On the form (using a query) create a control ImageFile

[Reference Number] & ".jpg"

2) Set-up (via a Function) the Image Path (this gives a little flexibility should you local and Server based images or FE and BE deployment of databases.

Code:
Function GetImageDir() As String
    GetImageDir = "drive:\Path\Images\
End Function

3) Then bring if altogether with another Function On Current Event on the Form
Code:
Function GetPicture()

Dim FullPath As String

    With CodeContextObject
        FullPath = GetImageDir & .[ImageFile]

        If Dir([FullPath]) <> Empty Then
            .[ImageControl].Visible = True
            .[ImageControl].Picture = FullPath
        Else
            .[ImageControl].Visible = False
        End If
    End With

End Function

Simon
 
Thank you so much Simon for providing the code.

I understand the theory of what you are suggesting - and I think it's spot on for what I am trying to do. so am quite pleased ;) - I just don't know how to go about it. I have given it a red hot go - but just don't know Access well enough to work it out. Can I ask (if you don't mind) - to walk me through. I will tell you what my questions are:

1) see your above: I don't know what a 'control Imagefile' is. So therefore I don't know how to create one. Although I tried two different things. a) clicked in my image box on the form and clicked control source(...)and just put that code in the expression builder. [see attach image1.jpg and image2.jpg]
b) created a query based I think on what you said (image3.jpg) - is that even correctly done? But just don't know what's what.

SO- FIRST QUESTION - How do I actually DO your first point.:o

2) How do I set up a FUNCTION. The only place I can see that again - is if I click on Control source(...) while after clicking on my image box - I see Function as an option - but other than that I am stuck. (image4.jpg)

SO - SECOND QUESTION - How do I actually DO your second point:o:o

3) THIRD QUESTION - so where do I put that code to bring it all together? :o:o:o

You can see my very basic knowledges is letting me down. If I can't get this working - I will just try and do it manually...eeeegggh.

Thank you:)
Katie
ps: I take your point about naming conventions...thanks for tip for future.
 

Attachments

  • image1.jpg
    image1.jpg
    86.8 KB · Views: 109
  • image2.jpg
    image2.jpg
    25.5 KB · Views: 107
  • image3.jpg
    image3.jpg
    54.9 KB · Views: 103
  • image4.jpg
    image4.jpg
    83 KB · Views: 94
I usually use a form based on a Query and create a field:

ImageFile: [Reference Number] & ".jpg"

On the Form I create a Text control Source = ImageFile

Again on the form create an Unbound Image control and leave blank, size accordingly.

Then create the Functions and then ON Current Event put =GetPicture()

Let me know where the images are located and map this in the Function GetImageDir().

Simon
 
Hi Simon, (I'm a fellow expat Kiwi too!)

The images are in a folder called 'images' relative to where the DB file is. so images\

Thanks, I will also see if I can work out what you are saying in your reply!

Katie
 
If you are keeping master images (50MB+) keep them away from the database volume. Someone explained to me when planning your volumes on drives (talking RAID) it is better to to keep a database on a relativity small volume as it is more efficient.

I would explicitly declare the Image Directory because if you ever change your mind or have a development version locally in a production server environment you can easily mange the location of the images.

Simon
 
Hi Simon,
Re your response:
"I usually use a form based on a Query and create a field:

ImageFile: [Reference Number] & ".jpg" "


I just don't understand that bit. sorry! Do I create a form (as in form wizard based on the table?)

On the Form I create a Text control Source = ImageFile

So I create a text field with the control source as ImageFile?


Again on the form create an Unbound Image control and leave blank, size accordingly.
Yep - understand that :)

Then create the Functions and then ON Current Event put =GetPicture()
The functions you wrote in your original reply? Do I put the rest of the code - or just =GetPicture()

Let me know where the images are located and map this in the Function GetImageDir().

Can you tell me where I put the function for GetImageDir() - Y ou mention it also in your point 2) in your first reply - I just don't know where to create that?

Thank you - I know I seem incredibly SLOW at this - but I am getting there - I promise. I so appreciate your help.!!

Thanks
Katie
 
Hi Simon,
Apart from the fact I want to cry :( - I have a client deadline looming and I can't believe I am stuck at the last hurdle. I actually thought this was going to be quite easy.

Do you think I could send you my DB and see if you can work out what I have done wrong- please? ....

Thanks
Katie
 
Hey there -
I have SOLVED IT!!

Thank you so much for your help here Simon. I really appreciate it.

BIG sigh of relief.

Cheers
Katie
ps: Go the Allblacks
 
Thanks Simon!,
I'm just curious - am I suppose to see images on your version?

Katie
 
Sorry

I forgot to say that you need to change the Function GetImageDir to location of the images.

Simon
 

Users who are viewing this thread

Back
Top Bottom