Code to use a field as a Hyperlink

  • Thread starter Thread starter LisaB
  • Start date Start date
L

LisaB

In Access you have to ability to select "Hyperlink" as the field datatype.

However, I have an Access 2000 front-end connected to a SQL 2000 back-end
and Hyperlink datatype is not an option.

On my form, I have a filed that holds a webAddress entered by the user. When
the user double-clicks on this field IE opens and goes to the webAddress.

I have the following code in the Double Click event
-----------
Private Sub WebAddress_DblClick(Cancel As Integer)

Shell "C:\Program Files\Internet Explorer\iexplore.exe " &
Me.WebAddress, vbMaximizedFocus

End Sub
 
On my form, I have a filed that holds a webAddress entered by the user. When
the user double-clicks on this field IE opens and goes to the webAddress.

I have the following code in the Double Click event
-----------
Private Sub WebAddress_DblClick(Cancel As Integer)

Shell "C:\Program Files\Internet Explorer\iexplore.exe " &
Me.WebAddress, vbMaximizedFocus

End Sub
-----------

Are there other ways to accomplish the same results?
What if the user is not using Internet Explorer or What if IE is not on the
C: drive in the specified path?

You can use "FollowHyperlink" to do this:

Application.FollowHyperlink Me.WebAddress

The catch is that the web address entered into the field must start with
"http://" or you must check for this and add it when appropriate. It is the
"http://" or "mailto:" (for generating a new email message) that tells
FollowHyperlink which action to take.
 
I get a RunTime Error '4': - Cannot connect to the Internet server - when I
use this as my Double Click Event
--------
Private Sub WebAddress_DblClick(Cancel As Integer)
Dim GOWeb As String

GOWeb = "http://" & Me.WebAddress

Application.FollowHyperlink GOWeb

End Sub
----------
 
I get a RunTime Error '4': - Cannot connect to the Internet server - when I
use this as my Double Click Event
--------
Private Sub WebAddress_DblClick(Cancel As Integer)
Dim GOWeb As String

GOWeb = "http://" & Me.WebAddress

Application.FollowHyperlink GOWeb

End Sub
----------

Are you sure that the [WebAddress] value in that record doesn't already contain
the "http://" in the string? You may need to check to see if [WebAddress] does
and, only if it doesn't, concatenate it to the start of the string.

'***Sample Code to add the prefix if not already present
If Left(Me.WebAddress, 7) <> "http://" Then 'No prefix
'Add the prefix
GOWeb = "http://" & Me.WebAddress
Else 'Prefix is already present
'Do not add the prefix
GOWeb = Me.WebAddress
End If
'***
 
It works. You only get the error if you double click on the field when it
is empty - I've put in code to handle it when the field is blank.

Thank You

Bruce M. Thompson said:
I get a RunTime Error '4': - Cannot connect to the Internet server - when I
use this as my Double Click Event
--------
Private Sub WebAddress_DblClick(Cancel As Integer)
Dim GOWeb As String

GOWeb = "http://" & Me.WebAddress

Application.FollowHyperlink GOWeb

End Sub
----------

Are you sure that the [WebAddress] value in that record doesn't already contain
the "http://" in the string? You may need to check to see if [WebAddress] does
and, only if it doesn't, concatenate it to the start of the string.

'***Sample Code to add the prefix if not already present
If Left(Me.WebAddress, 7) <> "http://" Then 'No prefix
'Add the prefix
GOWeb = "http://" & Me.WebAddress
Else 'Prefix is already present
'Do not add the prefix
GOWeb = Me.WebAddress
End If
'***
 
Back
Top