Still can't figure out FollowHyperlink

L

laura.dodge

Hi, I've tried to search online for what seems like it should be a
simple solution, but I still can't figure it out. I have a form in
Access 2003. I have a control called PubLink1 that is a hyperlink.
When I click on the hyperlink the pdf opens perfectly. However, to
make the form more user-friendly (and to save space) I would like to
create a command button called CmdPubLink1 that says 'Open
Publication' instead of having the user click on the hyperlink. Here's
what I have so far:

Private Sub CmdPubLink1_Click()
On Error GoTo Err_CmdPubLink1_Click

Application.FollowHyperlink PubLink1, , True

Screen.PreviousControl.SetFocus
DoCmd.FindNext

Exit_CmdPubLink1_Click:
Exit Sub

Err_CmdPubLink1_Click:
MsgBox Err.Description
Resume Exit_CmdPubLink1_Click

End Sub

When I click on the command button I get the warning message "Opening
"" Hyperlinks can be dangerous..." And then "Microsoft Office Access
can't follow the hyperlink to '#S:\File.pdf#'."

Does anyone see what I'm doing wrong? Thanks so much for your help!
 
D

Dirk Goldgar

laura.dodge said:
Hi, I've tried to search online for what seems like it should be a
simple solution, but I still can't figure it out. I have a form in
Access 2003. I have a control called PubLink1 that is a hyperlink.
When I click on the hyperlink the pdf opens perfectly. However, to
make the form more user-friendly (and to save space) I would like to
create a command button called CmdPubLink1 that says 'Open
Publication' instead of having the user click on the hyperlink. Here's
what I have so far:

Private Sub CmdPubLink1_Click()
On Error GoTo Err_CmdPubLink1_Click

Application.FollowHyperlink PubLink1, , True

Screen.PreviousControl.SetFocus
DoCmd.FindNext

Exit_CmdPubLink1_Click:
Exit Sub

Err_CmdPubLink1_Click:
MsgBox Err.Description
Resume Exit_CmdPubLink1_Click

End Sub

When I click on the command button I get the warning message "Opening
"" Hyperlinks can be dangerous..." And then "Microsoft Office Access
can't follow the hyperlink to '#S:\File.pdf#'."

Does anyone see what I'm doing wrong? Thanks so much for your help!


A hyperlink *field* is actually a text field that stores not only the
hyperlink address itself, but also optional parts such as the display text,
screen tip, and subaddress. The parts are all separated by "#" characters.
Because the field is marked as a hyperlink, when you just click on it,
Access knows to separate out the address part and "follow" it. When you use
the FollowHyperlink method in VBA code, though, you must pass just the
address itself, as a string.

You could use the Split() function to separate out the parts of the
hyperlink field, but there's a HyperlinkPart() function to make it easier.
Try this:

Application.FollowHyperlink HyperlinkPart(Me.PubLink1, acFullAddress)
 
L

laura.dodge

Thanks Dirk, that worked wonderfully!

For anyone else having a similar problem, I just wanted to let you
know that I took the following code out:

Screen.PreviousControl.SetFocus
DoCmd.FindNext

because it caused an error message saying "You didn't specify search
criteria with a FindRecord action."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top