More Understandable Error Message

K

Ken Hudson

I have a table in which I have set up a unique index based on two fields.
When a user tries to enter the same data twice through a form, they get the
generic message about duplicating the index, primary key, etc.
Is there a way to customize this error message?
 
A

Allen Browne

You can trap the message in the Error event of your form, and substitute it
with something more meaningful.

(Of course, it won't tell you *which* unique index is violated, so you will
need to determine that for yourself.)
 
F

fredg

I have a table in which I have set up a unique index based on two fields.
When a user tries to enter the same data twice through a form, they get the
generic message about duplicating the index, primary key, etc.
Is there a way to customize this error message?

You can use code to replace the system message with your own.

Here's how you can find the correct error and show your own message
for any of the form level errors.

First code the Form's Error event:

MsgBox "Error#: " & DataErr ' Display the error number
Response = acDataErrDisplay ' Display Default message

Then open the form and intentionally make that error.

The message box will display the error number and the default error
message.

Next, go back to the error event and change that code to:

If DataErr = XXXX Then
Response = acDataErrContinue ' Don't display the default
message
MsgBox "Present your own user friendly message here."
Else
MsgBox "Error#: " & DataErr
Response = acDataErrDisplay ' Display Default message
End If

where XXXX is the error number.
 
K

Ken Hudson

Perfect!
Thanks Fred.

--
Ken Hudson


fredg said:
You can use code to replace the system message with your own.

Here's how you can find the correct error and show your own message
for any of the form level errors.

First code the Form's Error event:

MsgBox "Error#: " & DataErr ' Display the error number
Response = acDataErrDisplay ' Display Default message

Then open the form and intentionally make that error.

The message box will display the error number and the default error
message.

Next, go back to the error event and change that code to:

If DataErr = XXXX Then
Response = acDataErrContinue ' Don't display the default
message
MsgBox "Present your own user friendly message here."
Else
MsgBox "Error#: " & DataErr
Response = acDataErrDisplay ' Display Default message
End If

where XXXX is the error number.
 

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