Hyperlink to .jpg file

LaurieW

Registered User.
Local time
Yesterday, 21:08
Joined
May 9, 2002
Messages
99
We have a telephone directory report in Access 2007. We would like to add a link to each staff person's photo. The photos are in a different location on our network, in our K: drive.

On the Access phone report, the text box holds the field StaffName and the text box is named txtStaffName.

Each photo is named with the staff member's name, for example: Brown_Sue.jpg. This name corresponds to the name on the phone list report.

I would like to add a hyperlink or a button (not the actual picture) to the side of each person's name on the report, so that when reading the phone list, users can click on the hyperlink/button to open the photo.jpg file that corresponds to that person. I have searched and read many posts on this forum, but haven't found anything that works. The closest I can get is to open the correct directory on K:. Here is what I have right now that does not work. This is in the On Click event of a button:

Private Sub cmdViewPhoto_Click()
On Error Resume Next
Dim sJPG As String
Dim sJPGPath As String
sJPGPath = "k:\web\prod\hr\staffphotos\files\"
sJPG = Dir$(sJPGPath & [txtStaffName] & ".jpg")
Application.FollowHyperlink sJPG
End Sub

Any clues as to how to get this to work? There has to be a way! Thanks.
 
How about simply:

Code:
Private Sub cmdViewPhoto_Click()
On Error Resume Next
Dim sJPG As String
Dim sJPGPath As String

sJPGPath = "k:\web\prod\hr\staffphotos\files\"
sJPG = sJPGPath & Nz(Me.txtStaffName, "1") & ".jpg"

   If Dir(sJPG) <> "" Then
      Application.FollowHyperlink sJPG
   End If
End Sub
 
Sweet! Yes, that works great. What does "Nz" mean or do? And what is the "1" for? I looked in VBA help for "Nz" but found nothing.

Thanks, thanks, thanks!!!
 
Nz handles NULLs. So, in this case it would create a bogus file name of 1.jpg and the Dir would return an empty string since it doesn't exist in the directory and therefore it would bypass the hyperlink. :)
 
Thanks for the explanation! I really appreciate your help. Thanks again!
 
I am trying to do the same but its not working for me. Can you please help thanks. Where can i put the code please?
 
Last edited:
I used this code on a report. I put the code on a button's On Click event.
 
hi Bob,

for some reason I tried following your code and I cannot get it to work :(

database:

primarykey
filename2

So I have some jpgs in filename2:

1.jpg
2.jpg
etc..

Then I created a simple form with filename2 (textbox) as a hyperlink. Then added your code (above) on an onClick event.

Nothing opens.. basically.. nothing happens.

Any ideas?

Thanks in advance,

Lisa
 
hi Bob,

for some reason I tried following your code and I cannot get it to work :(

database:

primarykey
filename2

So I have some jpgs in filename2:

1.jpg
2.jpg
etc..

Then I created a simple form with filename2 (textbox) as a hyperlink. Then added your code (above) on an onClick event.

Nothing opens.. basically.. nothing happens.

Any ideas?

Thanks in advance,

Lisa

1. don't set the text box to a hyperlink

2. You need the FULL PATH of the image, not just the name.
 
Thanks for your prompt reply! This is killing me. And I hate to request this.. could you put up an example .mdb of how this works?

Lisa
 
Thanks for your prompt reply! This is killing me. And I hate to request this.. could you put up an example .mdb of how this works?

Lisa
first of all, I'll do this as I'm kind of busy at the moment.

The structure of your table would be:

PHP:
PhotoID     PhotoName
1              C:\MyFolder\1.jpg
2              \\ServerName\Share\FolderName\2.jpg
3              F:\BigFolder\AnotherOne\Someother\My.jpg

Etc. And then the code I posted at the top would use the PhotoName field:
Code:
Private Sub cmdViewPhoto_Click()
On Error Resume Next
Dim sJPG As String
Dim sJPGPath As String

sJPG = Me.txtStaffName

   If Dir(sJPG) <> "" Then
      Application.FollowHyperlink sJPG
   End If
End Sub

or if the path is standard and then you have just what you have there with the

1.jpg
2.jpg

then it would be:
Code:
Private Sub cmdViewPhoto_Click()
On Error Resume Next
Dim sJPG As String
Dim sJPGPath As String

sJPGPath = "k:\web\prod\hr\staffphotos\files\"
sJPG = sJPGPath & Nz(Me.txtStaffName, "1") 
   If Dir(sJPG) <> "" Then
      Application.FollowHyperlink sJPG
   End If
End Sub
 

Users who are viewing this thread

Back
Top Bottom