Button to link to image

DEdmonds

New member
Local time
Today, 07:22
Joined
Apr 11, 2013
Messages
4
Dear All,

I'd like to put a button in a form that when clicked opens an image on the computer, the location of which is already specified in a field called RefImage.

When I change the hyperlink property I can only have the button open a folder or internet address rather than a unique image for each individual record.

If I use the code builder for the event on click and try to write Application.FollowHyperlink RefImage it gives me error message 490 that it Cannot Open the Specified File, but this is probably because I don't know how to write VBA.

Anybody know a simple way to make a button on a form open an image in IE or windows image viewer which has a path specified within a field of the form? Perhaps someway to use the Application.FollowHyperlink, clearly I am doing something wrong.

Bare with me as I don't have any programming experience and am new to Access, thanks in advance for your time and help,
 
To follow the hyperlink it must have HTTP:// in front of the website.

Use this code where website is the textbox with the URL that has to be followed. The If statement adds http:// if it isn't there yet.

Code:
 If Left(Me.website, 4) <> "HTTP" Then
    Me.website = "http://" & Me.website
    Else
    End If

Application.FollowHyperlink [website]
 
Thanks very much for the quick reply. Unfortunately, I think I did not explain the situation properly.

The images I am trying to link to are in a folder on the computer, not on the internet or accessible with http:/ The path to the images (each record has a different image path) is within a field in the table, example "C:\Users\user\Pictures\RefImages\image001.JPG"

I was hoping to be able to put a button on a form that when clicked references the path to the image file on the computer and then the image opens up in something like IE or windows photo viewer or something like this.

Thanks again, I appreciate it,
 
You can use Application.FollowHyperlink, if the file is registered with a program to open by default it will open up for you.. Example if JPEG files are associated to be opened with Windows Picture Gallery, it will open up the file..
 
Thanks for this. I must be doing something wrong, here is what I write in the code builder box

Private Sub RefImageButton_Click()

Application.FollowHyperlink (RefImage)

End Sub


Where RefImageButton is the name of the button and RefImage is the name of the field in the table which has the paths to the images.

When I switch back to Form View and click the button I get the following message: "Run-time error '490' Cannot open the specified file"

Here is what an example of what is in the column/field as a path to the image in case that is related to the problem:

C:\Users\user\Pictures\Reference_Photos\IMG_1679.JPG

Clearly I'm doing something wrong, but not knowing visual basics (so much so that I actually don't understand the information in the link to Application.FollowHyperlink above, I'm very very new to this! bare with me!) I'm not sure what it is. Can anyone see how to fix this? Thanks again,
 
Try

Private Sub RefImageButton_Click()

Application.FollowHyperlink [RefImage]

End Sub

notice that there is a space in between the JPG
C:\Users\user\Pictures\Reference_Photos\IMG_1679.J PG
 
Strange, it works for me.. Is the file definitely stored in that location? See if the RefImage returns the right location.. Try debugging, add a message box, before trying to open the pic..
Code:
Private Sub RefImageButton_Click()
    [COLOR=Red][B]MsgBox(Me.RefImage)[/B][/COLOR]
    Application.FollowHyperlink ([B]Me.[/B]RefImage)
End Sub
Also,
C:\Users\user\Pictures\Reference_Photos\IMG_1679.JPG
Is the user actually is how it is? Its not an actual user name is it?
 
If you have RefImage and the full file name is contained with this reference you do should not need a button to render the image onto the screen. I test if the image exists:

Code:
Function GetPicture()

    With CodeContextObject

        If GetPictureExist = True Then
            .[ImageControl].Visible = True
            .[ImageControl].Picture = GetPicturePath
        Else
            .[ImageControl].Visible = False
        End If
    End With

End Function

Simon
 
Appreciate the help guys. It works now!

Problem one was that the path to the image was not correct (I had deleted the _ on the folder name, doh!)

Problem two was the code, which works now that I have replaced it with the correct ones provided.

Spent all day today trying to figure it out but I guess it wasn't a waste to read through lots of old posts, learned a lot at least. Thanks for the time,
 

Users who are viewing this thread

Back
Top Bottom