MS Access 2007: Replace system error message with a custom message
This MSAccess tutorial explains how to replace the system error message with a custom message in Access 2007 (with screenshots and step-by-step instructions).
See solution in other versions of Access:
Question: In Microsoft Access 2007, I have a form that is linked to an Oracle table. When I enter duplicate data, I receive an error message "ODBC - failed... Unique Constraint violated...".
Is it possible to define a custom message to replace the system error message whenever the primary key is violated? (ie: duplicate record)
Answer: Yes, you can override the system error messages with your own messages. In your case, you want to place code on the Form's On Error event
.
For example, you could place the following code on the Form's On Error event
to trap the primary key violation:
Private Sub Form_Error(DataErr As Integer, Response As Integer) If DataErr = 3022 Then MsgBox ("You have violated the primary key.") Response = 0 End If End Sub
Now, whenever a user tries to enter a record that violates the primary key, the following error message will appear:
Advertisements