Trapping Error for Primary Key Violation

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?
 
W

Wayne Morgan

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.
 
M

maverick

can find the various responses. I have located 2 -

acDataErrDisplay

acDataErrContinue

but surely there must be other options..
 
W

Wayne Morgan

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top