The Errors Example

To better understand how the Errors collection of the Connection object works, I have come up with an example application conveniently named the Errors Collection Example.

This example allows you to execute an operation within ADO that will (hopefully) generate an error. In addition, you can add more error-generating code to the example to further investigate the usage of error handling within ADO.

The first form within the Errors Collection Example asks the user what type of error he would like to generate, as shown in Figure C-1.

The Errors Collection Example form
Figure C-1. The Errors Collection Example form

After the user selects an error from the list and presses the Ok button, the operation that generates the error or errors is attempted, and with any luck, the ADO Error(s) form is displayed detailing each error, as shown in Figure C-2.

The ADO Error(s) form
Figure C-2. The ADO Error(s) form

To begin this example, create a new project within Visual Basic, and be sure to set a reference to the Microsoft ActiveX Data Objects xx Library, where xx represents the version of ADO that you have on your machine (1.0, 1.5, 2.0, 2.1). Name the project ErrorsCollectionExample.

The Main Form

Once your new project is created, change the name of Form1 to frmErrorsCollectionExample, and add a label, a list box, and two command buttons, ...

Get ADO: ActiveX Data Objects now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.