Form Button to go to Website?

  • Thread starter Thread starter John Smith
  • Start date Start date
J

John Smith

I would like to put a button on my form such that when "pressed" opens up a
website.

The website address - or hyperlink - doesn't change and can be part of the
code.

Of course a more sophisticated version would refer to a hyperlink address
held in a table but I am happy with a hard coded solution.

Sorry if this is a simple question.

Kind regards
 
John Smith said:
I would like to put a button on my form such that when "pressed"
opens up a website.

The website address - or hyperlink - doesn't change and can be part
of the code.

Of course a more sophisticated version would refer to a hyperlink
address held in a table but I am happy with a hard coded solution.

Sorry if this is a simple question.

Simple version:

'----- start of code -----
Private Sub cmdWeb_Click()

Dim strWebURL As String

strWebURL = "YourWebSite.Com"

Application.FollowHyperlink "http://" & strWebURL

End Sub
'----- end of code -----

Note: the above code could have included the "http://" as part of the
URL literal, but my newsreader program (Outlook Express) insists on
removing the quotes and turning it into a hyperlink when I do that. So
for posting purposes, I did it this way.

Here's a version that looks up the URL in a table named "Configuration",
where it is stored in a field named "Website":

'----- start of code -----
Private Sub cmdWeb_Click()

Dim strWebURL As String

strWebURL = DLookup("Website", "Configuration")

Application.FollowHyperlink "http://" & strWebURL

End Sub
'----- end of code -----
 
Spot on solution - many thanks!

(I'd never found FollowHyperlink mentioned anywhere)

Kind regards
 
Back
Top