Trapping Error for Primary Key Violation

  • Thread starter Thread starter maverick
  • Start date Start date
M

maverick

Is there a way to trap MS Access errors that are inherent to the program? In
particular the one which describes primary key violations when adding new
records?
 
They can be trapped in the Form's OnError event. DataErr will give you the error number.
Response is what you tell access to do, probably "Response = acDataErrContinue" after
you've fixed the problem yourself.
 
can find the various responses. I have located 2 -

acDataErrDisplay

acDataErrContinue

but surely there must be other options..
 
The Access 2003 help file is a little better than the one in XP, I didn't
even find that much out there. However, the two you mention are the only two
I see. It also included an example:

Private Sub Form_Error(DataErr As Integer, Response As Integer)
Const conDuplicateKey = 3022
Dim strMsg As String

If DataErr = conDuplicateKey Then
Response = acDataErrContinue
strMsg = "Each employee record must have a unique " _
& "employee ID number. Please recheck your data."
MsgBox strMsg
End If
End Sub
 
Back
Top