The Syntax for the call is as follows:
Sub Form_Error(DataErr As Integer, Response As Integer)
__1. DataErr - contains the Error Number for the Error that just occurred.
__2. Response - Allows you to specify how you want Access to handle the Error. If your code handles the Error to your satisfaction and you don't want Access to intervene or display its own message, place the value acDataErrContinue in Response. If you want Acces to display its own Error Message, place acDataErrDisplay in Response.
The following code traps 4 Errors that might pop up. In each case, the procedure replaces the Standard Access Error Message with its own. If an Error occurs that it hadn't planned on, the Procedure just passes the responsibility back to Access:
Expand|Select|Wrap|Line Numbers
- Private Sub Form_Error(DataErr As Integer, Response As Integer)
- Const conErrDataValidation = 3317
- Const conErrDataType = 2113
- Const conErrDuplicateKey = 3022
- Const conErrNullKey = 3058
- Select Case DataErr
- Case conErrDataValidation, conErrDataType
- 'your Error Message here
- Response = acDataErrContinue
- Case conErrDuplicateKey
- 'your Error Message here
- Response = acDataErrContinue
- Case conErrNullKey
- 'your Error Message here
- Response = acDataErrContinue
- Case Else
- ' It's an unexpected error. Let Access handle it.
- Response = acDataErrDisplay
- End Select
- End Sub