Yes it would go in the AfterUpdate event of the primary key control but you would have to perform a check first to see whether the user was entering a duplicate record.
If they were then you could use the above code.
The Do whatever you want/do something else means what to do depending on what button the user presses.
The 65 in the MsgBox line of code tells Access what kind of Msgbox to display.
The VbOKCancel msgbox = 1
A VbInformation msgbox = 64
so add these together and you get an Ok/Cancel message box styled as an information box. Check out Access help for all the values or you can just type VbOkCancel+VbInformation instead of 65.
If the user pressed cancel you could stop the primary control losing focus so they could change what they entered, you'd do this by entering some code in the Else part of the above code where it says 'Do something else
If they pressed Ok you could just do nothing and let them carry on, so don't put any code in the part that says 'Do whatever you want.
Here's a better example:
DoCmd.SetWarnings = False
If MsgBox("Duplicate record entered.", 65, "Warning"

= vbCancel Then
[YourControl].SetFocus
End if
If you enter that into the AfterUpdate event and then have
Docmd.setwarnings = True
on the On Got Focus event of your control, you should be away.
HTH,
Pete