Key violation override

  • Thread starter Thread starter Crystal
  • Start date Start date
C

Crystal

I'm updating a table via a form. I have code that checks
to make sure that the value entered in the primary key
field is not present in the table. This is on the
BeforeUpdate procedure. I wanted to catch the error
before the user go to the end of the record, since there
are many fields and entry is time-consuming.

The code works, but after it's executed, I get the
standard "The value in the field or record violates the
validation rule for the record or field."

I don't need this because I already have a custom
message. Is there a way to supress this message?

Crystal
 
Hi:

Use the Form_Error event to trap the error and disable access error
reporting like this

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
Regards,

Naresh Nichani
Microsoft Access MVP
 
Back
Top