Link to home
Start Free TrialLog in
Avatar of Glynn071198
Glynn071198

asked on

putting url link on a form

how can i put url link on a form or command button
to my homepage
Avatar of Jason_G
Jason_G

Hi Glynn,
I believe what you are looking for here is the Hyperlink object.  Using the properties and methods of the Hyperlink object, your ActiveX document or ActiveX control can request a hyperlink-aware container, such as Microsoft Internet Explorer, to jump to a given URL.

You can use the NavigateTo method to jump to a URL. For example, the following code presumes an ActiveX document named "axdMyDoc" exists:
UserDocument.Hyperlink.NavigateTo _
"c:\mydocs\axdmydoc.vbd"
      
If your ActiveX document is contained by a hyperlink-aware container (such as Internet Explorer), and if the container maintains a history of documents, use the GoBack or GoForward methods to go backwards or forwards through the list. However, be sure to use error-checking, as shown in the example below:
Private Sub cmdGoForward_Click()
      On Error GoTo noDocInHistory
      UserDocument.Hyperlink.GoForward
      Exit Sub
noDocInHistory:
      Resume Next
End Sub

The syntax for using the NavigateTo method is as follows.

object.NavigateTo Target [, Location [, FrameName]]

The NavigateTo method syntax has these parts:

Part - Description

object - An object expression that evaluates to an object in the Applies To list.

Target - A string expression specifying the location to jump to. This can be a document or a URL.

Location - A string expression specifying the location within the URL specified in Target to jump to. If Location is not specified, the default document will be jumped to.

FrameName - A string expression specifying the frame within the URL specified in Target to jump to. If FrameName is not specified, the default frame will be jumped to.

Also, if the object is in a container that supports OLE hyperlinking, then the container will jump to the specified location. If the object is in a container that does not support OLE hyperlinking, then an application that is registered as supporting hyperlinking is started to handle the request.
If Target does not specify a valid location, an error is raised.

I hope this helps you.

Sincerely,
Jason

Jason Gorman (jason_gorman@scholars.com)
Learning Advisor, scholars.com
Microsoft Authorized Technical Education Center
Novell Authorized Online Training Provider
http://scholars.com
Avatar of Glynn071198

ASKER

thanks jason for for your help but im just a beginer and you lost me when you got to activeX controls. is there a simpler way? i really need some sample code to study. any suggestions on where i might find info.

Here's an easy method:

In your forms declarations add this:
Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (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

Place a label on a form.
In the OnClick handler for the label, put something like this:
nResult= ShellExecute( null, "open", "http://www.yourlink.com", "", "", 5)

dear rayb,
tryed pasting code in declaration and got this error:
(Constants, fixed length strings, arrays and declare statments
not allowed as public members of class or form modules.)
did i do something wrong?

ps, would like to run commamd from button or in menu
found something that works using the start.exe in windows\command directory

nResult = Shell("start.exe http://www.nascar.com", vbHide)

if you find something else let me know thanks
You will have better luck with ShellExecute in the long run, and the Hyperlink object in the longer run. As to ShellExecute, "Public Declares" are allowed only in regular modules. Put the declaration in a regular module or declare it "Private" in your form. Maybe Jason_G could give you some help on installing the Hyperlink control.
ASKER CERTIFIED SOLUTION
Avatar of movieguy
movieguy

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
works great thanks