Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how do you make a command button into a hyperlink to a website?

Status
Not open for further replies.

napjunk

Technical User
Dec 20, 2001
11
US
Ok, i know this is probably a very simple question, but, how do you make a command button into a hyperlink to a website?

like say the button says "Click here for support" and when you click it, it goes to in your default internet browser...
 
' Form Level Declarations
Private f_objIE as InternetExplorer.Application
'*******
Private command1_Click()
On Error Resume Next
Set f_objIE = CreateObject("InternetExplorer.Application")
if Err.Number <> 0 then
f_objIE.Navigate &quot; End if
On error goto 0
End Sub Compare Code (Text)
Generate Sort in VB or VBScript
 
Do i put the

Private f_objIE As InternetExplorer.Application

in Form_Load? or where? because i've tried form load and general declarations and it doesn't work
 
Put it in the form General Declarations. What does not work? What is the error message? You should already have a reference to Microsoft Internet Controls or change
Private f_objIE as InternetExplorer.Application
to
Private f_objIE as Object
but you lose Intellisense. Compare Code (Text)
Generate Sort in VB or VBScript
 
it says:

compile error:

User-Defined Type Not defined.

and highlights

f_objIE As InternetExplorer.Application

in General Declarations.

 
May I suggest another approach? Use the ShellExecute API. Here's an example:
Code:
Option Explicit
Private Declare Function ShellExecute Lib &quot;shell32.dll&quot; Alias &quot;ShellExecuteA&quot; (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

Private Sub Form_Load()
Call ShellExecute(Me.hwnd, &quot;open&quot;, &quot;[URL unfurl="true"]http://www.yahoo.com&quot;,[/URL] vbNullString, vbNullString, 0)
Unload Me
End Sub
All this does is open yahoo.com in IE, which is my defualt web browser. The advantage of this is that it will use the default web browser as opposed to relying on IE. Of course, almost every Windows system these days has IE installed, so it's not a really big deal to use it, but it's still better not to assume too much about your users' machines.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top