"if a primary key field left empty the msgbox appeared and asked me if I wanted to quit or not"
You cannot leave a primary key field blank, hence the error you are encountering. If you need to occasionally leave this field blank, I would recommend that it not be designated as the primary key. Could you assign an auto number field to the table and make that the primary key? If you could find a workaround for the assignment of the primary key, then you would not encounter this error.
However, if you want it to close w/o the field filled in, and then set the first line of the macro to Set Warnings to NO then the last line to Set Warnings YES. I don’t know if this will still allow what you are wanting, but it’s worth a try.
If that does not work, try converting the macro to code (TOOLS_MACROS_CONVERT MACROS) and in the error handler look for the line of code that says " MsgBox Err.Description". Change that to Err.Number, and run function again. When the message box appears, it will display a number instead of a description. Put an IF statement in the code to bypass the error message as such.
Exit_Command*_Click:
Exit Sub
Err_Command*_Click:
If Err.Number <> 2145 then
MsgBox Err.Description
Else
Resume Exit_Command6_Click
End IF
The * will be replaced by whatever you have assigned to your command button and the 2145 will be replaced by whatever Err.Number your system is generating.