Question : Closing of Internet Explorer at the end of a process in ms access 2003

Hi experts,

I found this code on this forum I think a couple of years back. The code looks at my website and extracts from the page a row of numbers.  Eg 01022010.

The code is working fine, but when the routine finishes, it is not closing internet explorer and the code just loops the next time i try and run the code. When I "break" the code, the line highlighed is "DoEvents" in the "Function PageContents".

I believe the code loops on the second time it is activated because internet explorer has not closed since the last time the code was run, but I could be wrong. Any help is so very much appreciated.

Regards

Terry
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
Function PageContents(sURL As String) As String
On Error Resume Next
Dim iz As New InternetExplorer

iz.Navigate sURL
Connect: Do Until iz.Busy = True

    DoEvents
Loop
    PageContents = CStr(iz.Document.Body.innerhtml)
    If Len(PageContents) > 0 Then
    Exit Function
    Else
    GoTo Connect:
    End If

End Function


Public Function BetweenHmm(ByVal sFrom As String, ByVal sStart As String, ByVal sEnd As String) As String
  Dim BegPos: BegPos = InStr(1, sFrom, sStart, 1)
  
  If BegPos > 0 Then
    BegPos = BegPos + Len(sStart)
    Dim EndPos: EndPos = InStr(BegPos, sFrom, sEnd, 1)
    If EndPos = 0 Then EndPos = InStr(BegPos, sFrom, vbCrLf, 1)
    If EndPos = 0 Then EndPos = Len(sFrom) + 1
    BetweenHmm = Mid(sFrom, BegPos, EndPos - BegPos)
  End If
End Function

Answer : Closing of Internet Explorer at the end of a process in ms access 2003

TerenceHewett,

As an alternative, the following checks it goes busy then completes ... you may want to play with the timeouts to allow normal completion but hopefully you gat the idea.

chris_bottomley
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
Function PageContents(sURL As String) As String
On Error Resume Next
Dim iz As New InternetExplorer
Dim cnt As Variant

    iz.Navigate sURL
    cnt = Now
    Do While iz.Busy <> True And Now < cnt + TimeValue("00:00:05")
        DoEvents
    Loop
    cnt = Now
    Do While iz.Busy = True And Now < cnt + TimeValue("00:00:10")
        DoEvents
    Loop
    
    PageContents = CStr(iz.Document.Body.innerhtml)
'    If Len(PageContents) > 0 Then
'        Exit Function
'    Else
'    End If

End Function



Public Function BetweenHmm(ByVal sFrom As String, ByVal sStart As String, ByVal sEnd As String) As String
  Dim BegPos: BegPos = InStr(1, sFrom, sStart, 1)
  
  If BegPos > 0 Then
    BegPos = BegPos + Len(sStart)
    Dim EndPos: EndPos = InStr(BegPos, sFrom, sEnd, 1)
    If EndPos = 0 Then EndPos = InStr(BegPos, sFrom, vbCrLf, 1)
    If EndPos = 0 Then EndPos = Len(sFrom) + 1
    BetweenHmm = Mid(sFrom, BegPos, EndPos - BegPos)
  End If
End Function
Random Solutions  
 
programming4us programming4us