trap "duplicate key" errors 
Author Message
 trap "duplicate key" errors

I have a table set for a unique index on certain fields.

When the user tries to input another record with the same "key" fields,
access generates an error msg about duplicate keys, etc.  That's fine and
normal.

But, I want to trap that error and offer my own message box with an option
for fixing the "problem" of their inputting a duplicate record.

How do I do that, and where do I put the onerror condition?  So far, none of
my choices seem to run first, I always get the access standard error msg.

Thanks!

--
Bill

PhotoSourceFolio webmaster
http://www.*-*-*.com/



Fri, 29 Mar 2002 03:00:00 GMT  
 trap "duplicate key" errors
You can use the Error event of the form to trap and suppress the
built-in message and substitute your own:

Private Sub Form_Error(DataErr As Integer, Response As Integer)
  Select Case DataErr
    Case 3022 'duplicate value
      MsgBox "Friendly message"
      Response = acDataErrContinue
  End Select
End Sub

Setting the Response parameter to acDataErrContinue is what suppresses
the built-in message.

 -- Andy

Quote:

>I have a table set for a unique index on certain fields.

>When the user tries to input another record with the same "key" fields,
>access generates an error msg about duplicate keys, etc.  That's fine and
>normal.

>But, I want to trap that error and offer my own message box with an option
>for fixing the "problem" of their inputting a duplicate record.

>How do I do that, and where do I put the onerror condition?  So far, none of
>my choices seem to run first, I always get the access standard error msg.

>Thanks!

>--
>Bill

>PhotoSourceFolio webmaster
>http://www.photosourcefolio.com



Sat, 30 Mar 2002 03:00:00 GMT  
 trap "duplicate key" errors
OK, that seems to work fine.

Now, if there is a duplicate, I want to clear out the current form's data so
they can continue on to the next item, which hopefully won't be a dup.

How do I cancel the current in-process add?

Thanks.

--
Bill

PhotoSourceFolio webmaster
http://www.photosourcefolio.com

Quote:
> You can use the Error event of the form to trap and suppress the
> built-in message and substitute your own:

> Private Sub Form_Error(DataErr As Integer, Response As Integer)
>   Select Case DataErr
>     Case 3022 'duplicate value
>       MsgBox "Friendly message"
>       Response = acDataErrContinue
>   End Select
> End Sub

> Setting the Response parameter to acDataErrContinue is what suppresses
> the built-in message.

>  -- Andy


> >I have a table set for a unique index on certain fields.

> >When the user tries to input another record with the same "key" fields,
> >access generates an error msg about duplicate keys, etc.  That's fine and
> >normal.

> >But, I want to trap that error and offer my own message box with an
option
> >for fixing the "problem" of their inputting a duplicate record.

> >How do I do that, and where do I put the onerror condition?  So far, none
of
> >my choices seem to run first, I always get the access standard error msg.

> >Thanks!

> >--
> >Bill

> >PhotoSourceFolio webmaster
> >http://www.photosourcefolio.com



Sat, 30 Mar 2002 03:00:00 GMT  
 trap "duplicate key" errors
Me.Undo

 -- Andy

Quote:

>OK, that seems to work fine.

>Now, if there is a duplicate, I want to clear out the current form's data so
>they can continue on to the next item, which hopefully won't be a dup.

>How do I cancel the current in-process add?

>Thanks.

>--
>Bill

>PhotoSourceFolio webmaster
>http://www.photosourcefolio.com


>> You can use the Error event of the form to trap and suppress the
>> built-in message and substitute your own:

>> Private Sub Form_Error(DataErr As Integer, Response As Integer)
>>   Select Case DataErr
>>     Case 3022 'duplicate value
>>       MsgBox "Friendly message"
>>       Response = acDataErrContinue
>>   End Select
>> End Sub

>> Setting the Response parameter to acDataErrContinue is what suppresses
>> the built-in message.

>>  -- Andy


>> >I have a table set for a unique index on certain fields.

>> >When the user tries to input another record with the same "key" fields,
>> >access generates an error msg about duplicate keys, etc.  That's fine and
>> >normal.

>> >But, I want to trap that error and offer my own message box with an
>option
>> >for fixing the "problem" of their inputting a duplicate record.

>> >How do I do that, and where do I put the onerror condition?  So far, none
>of
>> >my choices seem to run first, I always get the access standard error msg.

>> >Thanks!

>> >--
>> >Bill

>> >PhotoSourceFolio webmaster
>> >http://www.photosourcefolio.com



Mon, 01 Apr 2002 03:00:00 GMT  
 trap "duplicate key" errors
Try This!

On Form open

    DoCmd.SetWarnings False

On Form Error

    Your Code

On Form Close

    DoCmd.SetWarnings True

Kirk A. Viehland


Quote:
> I have a table set for a unique index on certain fields.

> When the user tries to input another record with the same "key" fields,
> access generates an error msg about duplicate keys, etc.  That's fine and
> normal.

> But, I want to trap that error and offer my own message box with an option
> for fixing the "problem" of their inputting a duplicate record.

> How do I do that, and where do I put the onerror condition?  So far, none
of
> my choices seem to run first, I always get the access standard error msg.

> Thanks!

> --
> Bill

> PhotoSourceFolio webmaster
> http://www.photosourcefolio.com



Thu, 04 Apr 2002 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Problems w/ trapping "TAB" key

2. How to trap the "Tab" key

3. Problems w/ trapping "TAB" key

4. trap "#Error" in query

5. Error trapping a "Find" dialog

6. Trap "No record found error"

7. Trapping "Out of Memory" error

8. Trap duplicate value error in primary key

9. Trap duplicate value error in primary key relationship

10. CDONTS Error : "Key does not exist"

11. disable keys like "key WIN", ctrl-ESC, ALT-TAB

12. Trapping "Expand", "Open", "Explore" in Windows Explorer?

 

 
Powered by phpBB® Forum Software