Intercepting Duplicate Error

K

Kevin Sprinkel

Can anyone tell me how to display a more user-friendly
message when a duplicate value is entered in a record on
which a unique multi-field index is maintained?

Thanks for any assistance.
 
G

Gerald Stanley

Kevin

Put validation into the AfterUpdate() method of the last
element of the multi-field index to test for uniqueness.

Hope That Helps

Gerald Stanley MCSD
 
K

Kevin Sprinkel

Thanks for your response.

I was hoping, though, to let Access test for uniqueness,
by virtue of a multi-field index (No Duplicates), and
simply cancel its message and display my own. Is it not
possible, then, to suppress this message?
 
J

John Spencer (MVP)

Use the OnError Event of the FORM and trap the error there.

Private Sub Form_Error(DataErr As Integer, Response As Integer)

Select Case DataErr
Case 1 '<<<--- whatever the error number is you are trapping
'first time through just trap it with the message box
'below and then you will know what it is and
'can change the case statement
MsgBox "Your Message here"
'corrective action here is possible
Response = acDataErrContinue '
Case Else
msgbox dataErr
Response = acDataErrDisplay 'let Access display its error msg

End Select

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