Trapping ADO errors is similar to trapping errors in most Visual Basic applications. You enable an error trap and write error-handling code to contend with errors that may occur. When you use error trapping the Err object is cleared for you. If you use inline error handling to handle errors without an error trap, you should use the Clear method to remove any existing error information before proceeding with code execution.
However, unlike other Visual Basic applications where you only rely on the Err object for error information, when you write ADO code you also need to use the ADO Errors collection to get more detailed information about an error or a group of errors from the data source.
When an error occurs or the data source returns a message, an Error object is created and added to the Errors collection. Error traps or inline code can interrogate the Errors collection and each specific Error object for more detailed information.
To see sample code that creates an error trap to support errors that may be returned while connecting to an external data source, click on the icon below.