Indexed field -- modify error message

T

tina

try creating a procedure in the form's OnError event to
trap the error code that produces the default error
message, then insert your own message instead, as

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

'this is a quick way to display the error number so you
can trap it.
MsgBox DataErr
'once you identify the error number, you can delete or
comment out the Msgbox line of code above.

If DataErr = 3022 Then
MsgBox "Duplicate serial number - please enter
unique serial number."
Response = acDataErrContinue
Me!SerialNumberField = Null
'the Null line of code is just a convenience, so the user
can just start typing again immediately after closing the
message box.
End If

End Sub

recommend you read up on the form's OnError event in Help,
so you'll understand the Response options available to you.

hth
 
T

Tom

Tina:

This is perfect!!! Thanks so much for the code!

One follow-up questions though...

After being prompted w/ the error box, the user can
immediately update/enter a unique value.

However, if this is ignored at that time, one can move
onto a new record. However, as you know, the value in
the last record (for that field is empty).

How can I ensure that I MUST enter a correct value before
anything else can be completed (i.e. creating new record)?

Thanks so much in advance,
Tom
 

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