In my previous post (#3) I mention both the
Form_Unload() and the
Form_Close() event procedures. The major difference between the two is that the
Unload event can be canceled, but the
Close event can't.
To ensure that no design changes are saved automatically when the form is closed have a Command Button on your form that handles closing. In there call for the close with code similar to :
- Call DoCmd.Close(ObjectType:=acForm, _
-
ObjectName:=Me.Name, _
-
Save:=acSaveNo)
It's also important to flag that the close has been called from your trusted routine rather than any other method (Red "X"; Ctrl-F4; etc.) so define a Boolean variable that is Private to the Form module which is typically unset (
False). In this routine add a line to set it to
True.
In
Form_Unload() check this variable and set the
Cancel parameter to
Not this variable. This will ensure that when any other method of closure is attempted the
Unload will cancel and the
Close won't proceed. Only your procedure will allow for the form to close, and it will ensure changes are never saved.
How to Close a Main Form Without Saving Changes of any Subforms has information on how to ensure nothing is upset when dealing with subforms.