HELP: Duplicate keys in Access Database 
Author Message
 HELP: Duplicate keys in Access Database

using VB5

How can i check for duplicate keys without getting "No Current Record"
error, when I add or edit. I use a data control.

I've tried all kinds of methods to get around this problem.

The file is Access, table type recordset, must have index on the file.
where can i check for duplicates - currently have check in validate
event when updating. Sample code would be GREATLY APPRECIATED.



Fri, 21 Jul 2000 03:00:00 GMT  
 HELP: Duplicate keys in Access Database

using VB5

How can i check for duplicate keys without getting "No Current Record"
error, when I add or edit. I use a data control.

I've tried all kinds of methods to get around this problem.

The file is Access, table type recordset, must have index on the file.
where can i check for duplicates - currently have check in validate
event when updating. Sample code would be GREATLY APPRECIATED.

                                          THANK YOU



Fri, 21 Jul 2000 03:00:00 GMT  
 HELP: Duplicate keys in Access Database

Timothy,

Seeking within the table using the same data control to verify the record's
existance is probably "ending" your current Edit/Add state for the record
to be added or updated.  You could try enabling error-handling in that
routine, then trap the error returned.  In this case, error number 3022 (I
think) will be returned if a duplicate key occurs.  For example:

-------------------------------------------------
Sub AnySub
    On Error Goto ErrorHandler

    With Data1.Recordset
        .Edit  (or .AddNew)
        <... edit or change fields, etc. >
        .Update
    End With

    Exit Sub

ErrorHandler:
    If Err.Number = 3022 Then
         < do whatever you want here when a duplicate key add is attempted.
         < this could also be a select case statement to handle multiple
error conditions. >
    EndIf
End Sub
---------------------------------------------

This code is not pulled from a program, so I can't guarantee it will
compile, but it should give you an idea of how to trap for the condition.

-- Vinnie

Quote:
> How can i check for duplicate keys without getting "No Current Record"
> error, when I add or edit. I use a data control.



Sat, 22 Jul 2000 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. HELP: Duplicate Keys in Access Database

2. VB & Access: duplicate inserts on unique key

3. Need Help with Duplicate Key Error

4. Help with record locking - duplicate key problem...

5. I am getting duplicate records, I mean everything is duplicate even Access record number

6. VB error trapping of duplicates in indexed Access database

7. Duplicating a Table in an Access Database

8. Duplicating a Table in a Access Database

9. Database Tables Disappearing - HELP HELP - Need Access Database specs

10. trap "duplicate key" errors

11. Duplicate Value in primary key - problem

12. Duplicate Value in Index/Primary Key Error

 

 
Powered by phpBB® Forum Software