Can t see any mistake in your code, Arage.
In fact, I couldn t eve reproduce your problem with a brand new table and form, thus confirming my suspicion: it must be provoqued by something else you made to your form.
Any .refresh or .requery for example would provoque an error since the duplicate PrimKey is not removed from the control yet.
That is why i use this duplicate key trapping in combination with (see my example above):
Sendkeys "{Esc}{Esc}" 'simulates manual suppression of the currently edited record
If you want to supress only the currently entered value :
SendKeys"{Esc}"
other wise, include this else statement in your on error code, to always get explicit description of the errors:
Private Sub Form_Error(dataErr As Integer, Response As Integer)
Const DuplicateKey = 3022
Dim strMsg As String
If dataErr = DuplicateKey Then
Response = acDataErrContinue
strMsg = "Duplicate, try again. "
MsgBox strMsg
Else:
Msg = "Error # " & Str(Err.Number) & " generated by " _
& Err.Source & Chr(13) & Err.Description
MsgBox Msg, , "Error", Err.Helpfile, Err.HelpContext
End If
End Sub
When you handle various error trapping routines, you may prefer to use a Select Case than If