HandsOn Writing the Report Error Event Procedure

1. In the Database window, rename the Customers table to Customers2.

2. Open the rptCustomers report you created in Hands-On 25-1 in Design view.

3. In the Visual Basic Editor Code window for the rptCustomers report, type the following Report_Error event procedure:

Private Sub Report_Error(DataErr As Integer, _ Response As Integer) ' obtain information about the error MsgBox Application.AccessError(DataErr), _

vbOKOnly, "Error Number: " & DataErr If DataErr = 3078 Then

MsgBox "Your custom error message goes here." End If

Response = acDataErrContinue End Sub

4. Run the rptCustomers report. When the input box appears prompting you for the criteria, type any letter and press OK. At this point the Report_ Error event will fire because the underlying data for the rptCustomers report does not exist. Because you renamed the Customers table that this report uses for its data source, Microsoft Access cannot locate the data, which generates the error.

5. In the Database window, rename the Customers2 table back to Customers and run the rptCustomers report to ensure that it does not produce unexpected errors.

0 0

Post a comment