<%dim crumb crumb="Error Event" crumb1="VBA Error Event" %> On Error Event
Home   Fees/Services   Access Templates   Tutorials  Tutorial Downloads   Articles   Search   Contact  Privacy  Links
<% response.write crumb2 %>
<% response.write crumb1 %>
 Home > Microsoft Access Tutorial > Form Event Tutorials <% response.write "> " & crumb %>

Access Event Tutorials:
Before Insert Event
After Insert Event
After Update Event
Before Update Event
Change Event
Close Event
Current Event
Double Click Event
Error Event
Exit Event
VBA Timer Event
Undo Event

Table-Level Events

Access Error Event Example

VBA Form Error Event Examples - Code Samples

Visual Basic Error event arises when a run-time error occurs in Access on the current form.

Error Event Visual Basic Example:

It is good practice to have an On Error event handler in each form.  In this example we simply trap the error and display a message to the user.

Private Sub Form_Error(DataErr As Integer, Response As Integer)
    Select Case DataErr
        Case 3022
            MsgBox "This field must contain unique values."
        Case 3023
            MsgBox "put appropriate error text here"
    End Select
    Response = acDataErrContinue
    Resume ok_exit
End Sub

The response argument can have either of two values:

acDataErrContinue:  Ignore the error and continue without displaying the Microsoft Access error message.

acDataErrDisplay:  Display the Microsoft Access error message. This is the default setting.

If you are using Global Variables in your Access database and you have a subroutine without an error handler then you will lose your global variable values if an error occurs.  This is one of the primary drawback in using Global Variables.

Form Triggers
Table Triggers
Form Flags
Table Triggers
Record Flags
Record Events

Microsoft Office:
MS Access 2003
Access 2007
Access 2010
Access 2013
Access 2016

Contact Information

<% Response.write "Copyright 2000-" & year(now) & " Blue Claw Database Design" %>