I'm guessing that you're using either Access 2007 or 2010. It has long been recommended that the code
If Me.Dirty Then Me.Dirty = False
be inserted before using
DoCmd.Close
to close a Form because of a quirk in Access. When DoCmd.Close is used, Access closes the Form regardless of whether or not a PK field or other Required Field has been left blank or validation rule has been violated! If one of these things occur, Access will simply dump the Record, close the Form, and not bother to tell the user that the Record has been dumped!
If Me.Dirty Then Me.Dirty = False
forces Access to attempt to save the Record, and if a violation has occurred, will throw up a warning message allowing correction to be made before closing the Form.
After years of not having addressed this bug, I understand that Microsoft sort of fixed it in ACC2007, by adding the above line to force the Save of the Record, when the Wizard is used to create a “Close” button. The problem is that this, in turn, has created another problem (what a surprise!) If you use the Wizard to create a “Close” button for an Unbound Form, which has no Dirty Property, the code bombs out!
Assuming that this is an Unbound Form, you need to either go into the code or, more likely, I'm guessing, the Macro created by the Wizard and remove the
If Me.Dirty Then Me.Dirty = False
line., or simply go into the OnClick event of the Button, delete the Macro completely, and insert the single line of code
DoCmd.Close
Linq ;0)>