Automaticly Creating Hyperlink based on user input

T

Tim McD

I have created code to automaticly create a hyperlink address based on user
input from a click of a command button. The purpose is that we are linking
to pdf file on our server to a field in a table. Each pdf has a unique name
that is associated to the CallSign field in the table. That field is set to
hyperlink. However When I select the command button and to generate the link
I get an "run-time error '7980' THe Hyperlink Address or SubAddress property
is read only for this hyperlink". What am I missing or can I do this some
other way? We have over 500 of these files and I dont want to manually creat
for each one using the link editor.


Dim lCallID, lHyper, lLinkAdd As String

Public Sub GenHyper()

Dim lCall, lLink, lExt As String
Dim dNum As Single

lCall = CallSign
lLink = "License\!Site&LicenseDatabase\"
lExt = ".pdf"
lCallID = lLink + lCall + lExt
lHyper = lCallID
lLinkAdd = lCallID
Lookup.IsHyperlink = True
Lookup.Hyperlink.Address = lLinkAdd
Lookup.Hyperlink.TextToDisplay = lHyper
End Sub

Private Sub Command60_Click()
Lookup.SetFocus
If Lookup.Text = "" Then
Call GenHyper
End If
Lookup.Hyperlink.Address = lLinkAdd

End Sub
 
J

John Nurick

Why not just use Application.FollowHyperlink?

I have created code to automaticly create a hyperlink address based on user
input from a click of a command button. The purpose is that we are linking
to pdf file on our server to a field in a table. Each pdf has a unique name
that is associated to the CallSign field in the table. That field is set to
hyperlink. However When I select the command button and to generate the link
I get an "run-time error '7980' THe Hyperlink Address or SubAddress property
is read only for this hyperlink". What am I missing or can I do this some
other way? We have over 500 of these files and I dont want to manually creat
for each one using the link editor.


Dim lCallID, lHyper, lLinkAdd As String

Public Sub GenHyper()

Dim lCall, lLink, lExt As String
Dim dNum As Single

lCall = CallSign
lLink = "License\!Site&LicenseDatabase\"
lExt = ".pdf"
lCallID = lLink + lCall + lExt
lHyper = lCallID
lLinkAdd = lCallID
Lookup.IsHyperlink = True
Lookup.Hyperlink.Address = lLinkAdd
Lookup.Hyperlink.TextToDisplay = lHyper
End Sub

Private Sub Command60_Click()
Lookup.SetFocus
If Lookup.Text = "" Then
Call GenHyper
End If
Lookup.Hyperlink.Address = lLinkAdd

End Sub
 
T

Tim McD

OK I used Application.FollowHyperlink with the command button. I still used
the link generator to direct it but it will not open the pdf. Here is was I
did...

Dim lCallID, lHyper, lLinkAdd As String

Public Sub GenHyper()

Dim lCall, lLink, lExt As String
Dim dNum As Single

lCall = CallSign
lLink =
"\\DOTGPOLYCVTRF01\Radio\RadioOps\!!SiteInformation\License\!Site&LicenseDatabase\"
lExt = ".pdf"
lCallID = lLink + lCall + lExt
lHyper = lCallID
lLinkAdd = lCallID
End Sub


Private Sub Command60_Click()
Call GenHyper
Application.FollowHyperlink lHyper
End Sub

Did I miss something? Or am I not understanding Application.FollowHyperlink?

Thanks for your help
Tim
 
R

Rob Oldfield

Where is CallSign specified? If you step through the code what does lCallID
get evaluated as?
 
T

Tim McD

Thanks Rob and John I got it to work. I used the Application.FollowHyperlink
and let the command button direct to the link. I cleaned up the code and
then used for two other fields on a different form were we are doing a
similar thing. I ended up with

Dim lCallID, lHyper As String

Public Sub GenHyper()

Dim lCall, lLink, lExt As String
Dim dNum As Single

lCall = CallSign
lLink = "License\!Site&LicenseDatabase\"
lExt = ".pdf"
lCallID = lLink + lCall + lExt
lHyper = lCallID
End Sub

Private Sub Command32_Click()
On Error GoTo Err_Command32_Click
Call GenHyper
Application.FollowHyperlink lHyper

Exit_Command32_Click:
Exit Sub
Err_Command32_Click:
MsgBox "No File Found", vbInformation, "Link"
Resume Exit_Command32_Click
End Sub

Thanks again for your help
Tim
 

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