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

On Error won't work for Loop Code pasting Info on Internet

Status
Not open for further replies.

BillieBurgess

Technical User
Jul 2, 2002
36
US
I created a form that loops through records pasting the information onto the vendor’s website and then moves onto the next record.
The problem is that sometimes due to a slow connection either on our side or the vendors, the code debugs due to the page not pulling up in time. I wrote an on Error line for the code to skip to the next record and continue. However, the debug still comes up. It doesn't follow the on error message at all. I can't figure out why and was hoping someone might help.
Here is the code:

Code:
Private Sub NoteAllRecordsEWeb_Click()
On Error GoTo Err_NoteAllRecordsEWeb_Click
    If IsNull(User) Then
    MsgBox "Please enter your Initials"
    GoTo Exit_NoteAllRecordsEWeb_Click
    End If
    Dim obIE As SHDocVw.InternetExplorer
    Dim strText As String
    Dim vURL As String
    Dim stMsg As String
    Dim strCSGACCTNUMBER As String
    Dim strWORKORDERNUMBER As String
    
        Me.RecordsetClone.MoveFirst
    If Me.RecordsetClone.RecordCount > 0 Then

AddEWebNotes:
        Do Until Me.RecordsetClone.EOF
            Me.Bookmark = Me.RecordsetClone.Bookmark
        If IsNull([CSGACCTNUMBER]) Then
            MsgBox "CSG Account Number is not Entered", vbOKOnly
            Me.RecordsetClone.MoveNext
        End If
        strText = Me!Note.Value
        strCSGACCTNUMBER = [CSGACCTNUMBER]
        vURL = "https:websiteURL.cfm?ACCTNO=" & strCSGACCTNUMBER
 
    'Create the IE Object
        Set obIE = CreateObject("InternetExplorer.Application")
        While obIE.Busy = True
            DoEvents
        Wend
            obIE.navigate vURL
        While obIE.Busy = True
            DoEvents
        Wend
            obIE.FullScreen = False
            obIE.Visible = True
        While obIE.Busy = True
            DoEvents
        Wend
        With obIE.Document
            .all.Item("accountMemo").Value = strText
            .Forms("memoForm").submit
        While obIE.Busy = True
            DoEvents
        Wend
        End With
        EWEB = Environ("UserName")
        [E-CONNECTDATE] = Date
        obIE.Quit
        Me.RecordsetClone.MoveNext
    Loop
    End If
    Me.RecordsetClone.Close
    
Exit_NoteAllRecordsEWeb_Click:
'Closes and Reopens Form to See any Records that were skipped
    DoCmd.Close acForm, "frmEWeb", acSaveNo
    DoCmd.OpenForm "frmEWeb", acNormal, , , acFormEdit, acWindowNormal
    Exit Sub
    
Err_NoteAllRecordsEWeb_Click:
'Skip and move to the next record if there is an error
        Me.EWEB = Null
        Me.RecordsetClone.MoveNext
        GoTo AddEWebNotes
End Sub
 
BillieBurgess,
A couple of thoughts.[ol]
[li]Do you have the VBE set to Break on All Errors by chance (Tools=>Options, General tab)?[/li]
[li][tt]obIE.Busy[/tt] changes states a lot while a page is loading. In my experience this is a more reliable way to make sure the page is done. [tt]While obIE.Object.Document.ReadyState <> "complete"[/tt].[/li]
[li]Do you need to [tt]obIE.Quit[/tt] in your error handler?[/li]
[li]Instead of closing and reopening the form you might try [tt]Me.Requery[/tt].[/li][/ol]

If number one above is set to Break on Unhandled Errors I'm curious which line is [highlight]highlighted[/highlight] when you select Debug.

Hope this helps,
CMP

[small]For the best results do what I'm thinking, not what I'm saying.[/small]
(GMT-07:00) Mountain Time (US & Canada)
 
1. I have Break on UnHandled Errors
It Highlights While obIE.Busy = True after both the obIE.navigate vURL and the obie.visible
2. I changed all of the obie.busy to the obIE.Object.Document.ReadyState <> "complete". and will see if it works today.
3. We paste on average about 600 notes each with a different account. Regarding the obie.quit I need the page to close because each 'note' is pasted onto that accounts note screen. This is the only way I know how to do it. Is there a better way?
4. Thanks I will, I sometimes overlook the obvious.
 
Anyway, your error handler should use the Resume instruction instead of GoTo

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top