error 3022 (double values in index)

  • Thread starter Thread starter Wim
  • Start date Start date
W

Wim

Hi all,

Is it possible the programmatically trap the error 3022,
which occurs when trying to insert a double value for a
key that does not allow for duplicates ? I now arrive in
the VB-screen, which is not something I want my customers
to drop in.

Thank you very much,

Wim
 
At the top of your VBA Procedure insert the following:

On Error Goto errorHandler


Then at the bottom of the procedure just before End Sub
(or whatever), put the following:

errorHandler: 'label
if(err.Number=3022)then
do something
else
do something else
Endif

You can generate a message for error 3022 that's generic
like: msgbox "You have previously entered this record..."

If the error is something other than 3022 you can build a
message something like the following:

msgbox "Error Number " & err.Number & " - " &
err.Description.

Check help for error handling for more details on the
different error handling objects.

Hope that helps!

Kevin
 
This will only work if it is your code that is trying to enter the duplicate.
If it is the user entering data you need to use the Form OnError event to trap
the error. 3022 will be the value of DataErr. Display your own message then
use Response = acDataErrContinue to suppress the Access error.
 
Back
Top