Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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.