• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL

Chapter 16. Error Handling: Preparing fo... > Using the Errors Collection

Using the Errors Collection

The Errors collection is part of Access's Jet Engine. It stores the most recent set of DAO errors that have occurred. This is important when dealing with DAO (Data Access Objects) and ODBC (Open Database Connectivity), in which one operation can result in multiple errors. If you are concerned with each error generated by one operation, you need to look at the Errors collection. Each error object in the Errors collection contains information about an error that occurred. If you want to view the errors stored in the Errors collection, you must loop through it, viewing the properties of each Err object. Listing 16.12 shows the code you can use to accomplish this.

Listing 16.12. Viewing the Errors Stored in the Errors Collection

Sub TestErrorsCollection()
    'Invoke error handling
    On Error GoTo TestErrorsCollection_Err

    'Declare a DAO database object
    Dim db As DAO.Database

    'Point the database object at the database
    'referenced by the CurrentDB object
    Set db = CurrentDb

    'Attempt to execute a query that doesn't exist
    db.Execute ("qryNonExistent")

    Exit Sub


    Dim ErrorDescrip As DAO.Error

    'Loop through the Errors collection,
    'sending the error number and description to
    'the Immediate window
    For Each ErrorDescrip In Errors
        Debug.Print ErrorDescrip.Number
        Debug.Print ErrorDescrip.Description
    Next ErrorDescrip
    Exit Sub
End Sub




Not a subscriber?

Start A Free Trial

  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint