Error Trapping - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Error Trapping

LangatLangat Posts: 2Member
How can I trap errors during runtime before they are raised by the running program, following is part of my code in vb 6
if rst.bof = false
my program raises ".BOF is true error" yet I want to trap it before the program reports it during run time.

Comments

  • dokken2dokken2 Posts: 532Member
    : How can I trap errors during runtime before they are raised by the running program, following is part of my code in vb 6
    : if rst.bof = false
    : my program raises ".BOF is true error" yet I want to trap it before the program reports it during run time.
    :
    :
    The ON ERROR GOTO and RESUME statements trap errors-

    [code]
    Private Sub Command1_Click()
    Dim db As DAO.Database
    Dim rs As DAO.Recordset

    'TURN ON ERROR HANDLING
    On Error GoTo errHandler

    Set db = currentdb
    Set rs = db.OpenRecordset(SQL, dbOpenSnapshot)

    Do While Not rs.EOF
    Debug.Print rs!field1
    rs.MoveNext
    Loop

    xit:
    rs.Close
    db.Close
    Set rs = Nothing
    Set db = Nothing
    Exit Sub

    errHandler:
    MsgBox Err.Description, vbCritical, Err.Number
    'Resume Next 'RESUME NEXT STATEMENT *AFTER* WHERE ERROR OCCURED
    Resume xit 'RESUME SPECIFIC STATEMENT
    End Sub
    [/code]
Sign In or Register to comment.