Form Button to go to Website?

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
 
D

Dirk Goldgar

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 -----
 
J

John Smith

Spot on solution - many thanks!

(I'd never found FollowHyperlink mentioned anywhere)

Kind regards
 

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