Link to home
Start Free TrialLog in
Avatar of Baikie
Baikie

asked on

Cannot get 'Followhyperlink' to work

Trying to add hyperlinks to PDF spec sheets in my database. Have a button with the following on_click event

FollowHyperlink Me![SpecSheet]

where Me![SpecSheet] is the path to the document stored in the database.

However when i click the button i get runtime error 7971, cannot follow hyperlink '#\\server\folder\filename.pdf#'

I don't know where it is picking up the '# from.

Any ideas?
Avatar of stevbe
stevbe

Is the path correct?
Do you have permission to the pdf?
Does it work if you out the path in the Hyperlink property?

Steve
You can also try this (example is from behind a command button):

On Error GoTo ClickError:
Dim ctl As CommandButton
    Set ctl = Me!Command1    'number/name of your command button
    With ctl
        .Visible = True
        .HyperlinkAddress = "\\spfp02\custcare\filename.xls"    'you file address
        .Hyperlink.Follow
    End With

ClickExit:
Resume Exit Sub

ClickError:
Msgbox ("Incorrect address")
Resume ClickExit:

End Sub
This goes to your hyperlink address and opens the file/web page etc...

If the hyperlink you typed in is wrong, a message box will tell you.
You can adapt it to your entry field as:

On Error GoTo ClickError:
Dim ctl As CommandButton
    Set ctl = Me!Command1    'number/name of your command button
    With ctl
        .Visible = True
        .HyperlinkAddress = "" & [Your Entry] & ""    'your file address
        .Hyperlink.Follow
    End With

ClickExit:
Resume Exit Sub

ClickError:
Msgbox ("You have entered an incorrect address.")
Resume ClickExit:

End Sub

Again, this will tell the user that the entered address is wrong.
## Sorry

ClickExit:
Resume Exit Sub

Should be

ClickExit:
Exit Sub

Sorry...   :-)
ASKER CERTIFIED SOLUTION
Avatar of rockiroads
rockiroads
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Baikie

ASKER

Thanks for all the replies!

stevbe:

Path is correct and permissions are all ok.

dannywareham:

Tried out your solution but came back with the same error as before.

rockiroads:

Eureka! This worked fine. Points to you.

Does anyone know why access was adding in the # sign?

Many Thanks,

Baikie
I noticed when u change the fieldtype of hyperlink to a string, it does it, dont know why, thats the only time Ive found it, there may be more, I dunno
the # is used to separate the hyperlink from the hyperlink description and the "bookmark".  i don't remember exactly, but i think a hyperlink must be given in the format

  description#URL#bookmark   (while the '#bookmark' part is optional, i think)

try setting Me![SpecSheet] to

  TheHyperlinkDescription#http:\\www.whatever.com

as i wrote, i don't remember exactly, and i don't remember where i saw it, either...  so this is a vague suggestion; you might have to try different combinations, like

  http:\\www.whatever.com#TheHyperlink

or so.


--bluelizard
ok, now i found out about it: when you store a hyperlink in a hyperlink field, it *looks* like a regular hyperlink, but internally, it's stored as

  TextToDisplay#http://www.theURL.com#

(you can see that if you change a table's hyperlink field into a text field: the hyperlinks that are already in the table are converted to strings that look like the one above).

maybe you should try the format above.

anyway, to enter a hyperlink into a hyperlink field, it's easiest to use

  Me.MyHyperlinkField.SetFocus
  RunCommand acCmdInsertHyperlink

then, the link gets inserted in the right format.


--bluelizard