For example, you could place the following code on the Form's On Error event to trap the primary key violation:
Private Sub Form_Error(DataErr As Integer, Response As Integer)
If DataErr = 3146 Then
MsgBox ("You have violated the primary key.")
Response = 0
End IfEnd Sub
Now, whenever a user tries to enter a record that violates the primary key, the following error message will appear: