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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding Hyperlinks to Form/Database to Connect to Internet 1

Status
Not open for further replies.

SteverZ

Technical User
Nov 8, 2000
16
0
0
US
VB6.0 Enterprise Edition. Trying to hyperlink to the interent does not work.
* Form1
TxtField(1) ... displays name
TxtField(2) ... displays URL
TxtField(3) ... linked using Adodc1. I click on > or >>| to see
what is next in line in my database.
CmdGo ......... press and the displayed URL website in
TxtField(2)should open in Internet Explorer
Add,Delete ... I also have Add, Delete and Update buttons since
I have a second form, Form2

* Form2 .... this is my database, Form2.mdb. I can add new names
and URLs to my database using this Add feature.

Here is the code behind CmdGo: 'Command Button

Private Sub cmdGo_Click()
On Error GoTo Errorhandler
Set Explorer = New SHDocVwCtl.InternetExplorer
Explorer.Visible = True
Explorer.Navigate txtField(2).Text
Exit Sub

Errorhandler:
MsgBox "Error displaying file for web site"

End Sub

I placed these lines in the Form Declarations:
Option Explicit
Dim varBookMark As Variant
Public Explorer As SHDocVwCtl.InternetExplorer

* No Hard-Coding the URL - Hard coding the URL into the program is NOT what I need. Doing that means having to constantly open the project, add the new URL, make a new EXE, and destroy the old one. What I am after, as you can see, is being able to Add new URLs constantly (which I am now doing)and then go to websites by clicking on the "GO" Command Button from my program. This should work, but I just don't know what is missing.

Can anyone help? Please be simple and specific with your suggestions and codes. Thank You.
 
Assumptions: You're working in a closed environment where OS's and Browsers are part of a corporate standard. If this is the case, my solution should work with Windows 95/98/NT/2k with IE 4+ browsers.

There is an API Call named ShellExecute.

Public 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

In your code, you can use:

ShellExecute Me.hwnd, &quot;open&quot;, <URL as String>, &quot;&quot;, App.Path, 0

This will replicate the behavior of typing the url into the RUN dialog.

Hope this helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top