
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.