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!

Problem Connecting to Internet w/VB . Code is here. Help!

Status
Not open for further replies.

SteverZ

Technical User
Nov 8, 2000
16
0
0
US
I have a VB form (VB6.0 Enterprise) with several textboxes and command buttons for Add, Delete, Update & Refresh. I also have a command button "cmdGo" that when clicked, should open Interent Explorer browser and go to the site that is listed in "txtField(2)". When I click on "GO" command button, what I get instead though, is the error message that I placed into my program "Error displaying file for web site". I cannot get to any websites.

I have a second form that is linked to a .mdb file that holds the website names and URLs that I created using VisData (I do NOT have Access at home, so VisData will do fine for this.) It's at this .mdb that I store the website names, which show up on my main form in txtField(0) with the URL being in txtField(1). The DataField for txtField(2) is set to pick-up whatever is in txtField(1), with txtField(1) having the complete URL. Therefore, all of the connections/relationships are correct.

Below is the code. Can you find where the problem(s) is/are? All of the features work great, except connecting to the internet when pressing the "Go" command button [Private Sub cmdGo_Click()].

Thanks.


Option Explicit
Dim varBookMark As Variant
Public Explorer As SHDocVwCtl.InternetExplorer

Private Sub Adodc1_MoveComplete(ByVal adReason As.EventReasonEnum, _
ByVal pError As ADODB.Error, _
adStatus As ADODB.EventStatusEnum, _
ByVal pRecordset As ADODB.Recordset)

lblRecord.Caption = "Record: " & _
CStr(Adodc1.Recordset.AbsolutePosition) & _
" of " & Str(Adodc1.Recordset.RecordCount)
End Sub


Private Sub cmdAction_Click(Index As Integer)
On Error GoTo goActionErr
With Adodc1

Select Case Index

Case 0 'Add
If cmdAction(0).Caption = "&Add" Then
varBookMark = .Recordset.Bookmark
.Recordset.AddNew
txtField(0).SetFocus
cmdAction(0).Caption = "&Cancel"
SetVisible False
Else
.Recordset.CancelUpdate
If varBookMark > 0 Then
.Recordset.Bookmark = varBookMark
Else
.Recordset.MoveFirst
End If
cmdAction(Index).Caption = "&Add"
SetVisible True
End If

Case 1 'Delete
If .Recordset.EditMode = False Then
.Recordset.Delete
.Recordset.MoveNext
If .Recordset.EOF Then .Recordset.MoveLast
Else
MsgBox "Must update or refresh record before deleting!"
End If

Case 2 'Update
.Recordset.Update
varBookMark = .Recordset.Bookmark
.Recordset.Requery
If varBookMark > 0 Then
.Recordset.Bookmark = varBookMark
Else
.Recordset.MoveLast
End If
cmdAction(0).Caption = "&Add"
SetVisible True

Case 3 'Refresh
varBookMark = .Recordset.Bookmark
.Refresh
If varBookMark > 0 Then
.Recordset.Bookmark = varBookMark
Else
.Recordset.MoveLast
End If

End Select

End With

Exit Sub

goActionErr:

MsgBox Err.Description

End Sub

Private Sub cmdExit_Click()
Unload Me
Set frmSecret = Nothing
End Sub

Private Sub cmdGo_Click()
On Error GoTo Errorhandler
Set Explorer = New SHDocVwCtl.InternetExplorer
Explorer.Visible = True
Explorer.Navigate txtField(2)
Exit Sub
Errorhandler:
MsgBox "Error displaying file for web site"

End Sub

Private Sub cmdGrid_Click()
Secret_Web_Sites.Show
End Sub

Private Sub cmdNegotiate_Click(Index As Integer)
On Error GoTo goNegotiateErr
With Adodc1.Recordset

Select Case Index
Case 0 'First Record
.MoveFirst
Case 1 'Previous Record
.MovePrevious
If .BOF Then .MoveFirst
Case 2 'Next Record
.MoveNext
If .EOF Then .MoveLast
Case 3 'Last Record
.MoveLast

End Select

End With

Exit Sub

goNegotiateErr:
MsgBox Err.Description

End Sub

Public Sub SetVisible(blnStatus As Boolean)

Dim intIndex As Integer

For intIndex = 0 To 3
cmdNegotiate(intIndex).Enabled = blnStatus
Next intIndex

cmdAction(1).Enabled = blnStatus 'Delete
cmdAction(3).Enabled = blnStatus 'Refresh

End Sub

 
this may or may not help:

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

Public Function OpenLocation(URL As String, windowState As Long) As Long
Dim lHWnd As Long:Dim lAns As Long

lAns = ShellExecute(lHWnd, "open", URL, vbNullString, vbNullString, windowState)
OpenLocation = lAns
End Function
 
Hi SteverZ,

You might try this example:
Code:
Private Sub cmdGo_Click()
Dim myApp
Dim strFilepath As String
Dim strURL As String

strFilepath = "c:\program files\internet explorer\iexplore.exe"
strURL = " [URL unfurl="true"]www.yahoo.com"[/URL]
myApp = Shell(strFilepath & strURL, 1)
End Sub

Don't forget the leading space in strURL
Hope this helps,
Tim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top