Error

The Error event is triggered by errors in accessing the data for the report. Use this event to replace the default error message with your custom message. The Error event takes the following two arguments:

DataErr — Contains the number of the Microsoft Access error that occurred.

Response — Determines whether or not error messages should be displayed. It may be one of the following constants:

acDataErrContinue — Ignore the error and continue without displaying the default Microsoft Access error message. AcDataErrDisplay — Display the default Microsoft Access error message. This is the default.

The Report_Error event procedure in Hands-On 25-7 illustrates how to use the value of the DataErr argument together with the AccessError method to determine the error number and its descriptive string.

The statement

Response = acDataErrContinue will prevent the standard Microsoft Access error message from appearing. The Error event for reports works the same as the Error event for forms — but only the Microsoft Access or the Jet Engine errors can be trapped here.

To trap errors in your VBA code, use the On Error GoTo statement to direct the procedure flow to the location of the error-handling statements within your procedure.

Event Programming in Forms and Reports

0 0

Post a comment