send user to a website

  • Thread starter Thread starter Mark Kubicki
  • Start date Start date
M

Mark Kubicki

What kind of code would I need to add behind a double click event to send a
user to a website? The text box that would have the event is linked, in a
related table, to a hyperlink, but in itself not one.

thanks in advance,
mark
 
Private Sub MyTextbox_DblClick(Cancel As Integer)

Application.FollowHyperlink " http://www.microsoft.com "

End Sub

(note that spaces between the URL and quotes shouldn't actually be there. I
had to include them though, because otherwise Outlook Express would have
removed them)
 
Mark Kubicki said:
What kind of code would I need to add behind a double click event to send
a user to a website? The text box that would have the event is linked, in
a related table, to a hyperlink, but in itself not one.


You can use FollowHyperlink method to follow any string URL. For example:

Application.FollowHyperlink "http://www.datagnostics.com"

or

Dim strLink As String

strLink = DLookup("Website", "SomeTable")

If Left(strLink, 4) <> "http" Then
strLink = "http://" & strLink
End If

Application.FollowHyperlink strLink
 
Mark Kubicki said:
possibly because dlookupis returning a hyperlink, i'm getting:
http://#http://www.datagnostics.com# as the value for strLink (note the 2
"#"s), and attempts to strip them are alluding me... any suggetions?


Yes, a hyperlink field is a text field made up of several parts separated by
'#' characters. You have to extract the second part, which is the actual
web address. Doug Steele's suggestion to use the Split function is good.
Here's an approach that should work (I think) whether the field is a
hyperlink field or plain text:

Dim strLink As String

strLink = DLookup("Website", "SomeTable") & vbNullString

If InStr(strLink, "#") > 0 Then
strLink = Split(strLink, "#")(1)
End If

If Left(strLink, 4) <> "http" Then
strLink = "http://" & strLink
End If

Application.FollowHyperlink srtrLink
 
thanks, it cleaned up the screen perfectly; however, the application command
does not appear to execute. Is there a switch somewhere that needs to be
activated?

-mark

----------------------------------------------------------------------
 
Mark Kubicki said:
thanks, it cleaned up the screen perfectly; however, the application
command does not appear to execute. Is there a switch somewhere that
needs to be activated?

You mean you don't see the hyperlink being followed? That's odd. Bear in
mind that, with modern tabbed browsers, it will not normally open a new
browser window if there's one open. Instead, it will open another tab in
the current browser. I would expect it to activate that browser window so
you can see it; however, there are some circumstances in which it doesn't
do that.

Try going to the Immediate window and entering

Application.FollowHyperlink "http://google.com"

Does that work? Can you then find that web page in any browser you have
open? It probably won't activate the browser window under these
circumstances.
 
typing Application.FollowHyperlink "http://google.com" in the immediates
window worked
the line of code behind the form does not...

hmpft? (must be "something")

-mark
----------------------------------------------------------------------------------------
 
Mark Kubicki said:
typing Application.FollowHyperlink "http://google.com" in the
immediates window worked
the line of code behind the form does not...

hmpft? (must be "something")


Set a breakpoint on the FollowHyperlink line, then trigger the event. When
the code halts at that line, check the value of strLink to make sure it's
what you think it should be.
 
Douglas J. Steele said:
Application.FollowHyperlink Split(strLink, "#")(1)

I just happened to be looking at this for a demo to my user group and I find
that both of the following work successfully on a hyperlink field:

Application.FollowHyperlink Me!WebSiteHyperlink, True

or

Application.FollowHyperlink Split(Me!WebSiteHyperlink, "#")(1), True

I know what the Help and Intellisense say: Address as String. But it works
this way, as well. It works even if I used "Insert Hyperlink" to fill the
hyperlink field, and set Text to Display a text name not a text copy of the
URL and the actual hyperlink text to the URL.

Larry Linson
Microsoft Office Access MVP
 
Back
Top