- Local time
- Today, 07:47
- Joined
- Feb 28, 2001
- Messages
- 29,065
You have the option (with Form_Unload AND/OR with Form_BeforeUpdate) to set CANCEL=TRUE to prevent an update from occurring, either by a SAVE button or navigation away from a record (which does an automatic update) or a form closure (which does an automatic update). At the point where you do a CANCEL=TRUE, the update or unload event will not proceed. The form remains open as though the user action that triggered the event never happened. At that time, you have a chance to do something and a choice of what to do.
You CAN just say "continue to fill in blanks to finish the operation" and then when your user tries to save or close the form, eventually the validation code could say "OK, this is acceptable" - at which moment you would do all of the primary and secondary update actions discussed earlier like updating the details and updating the main-table status.
OR you can say "If you are going to close the form in an incomplete state then I will not allow this to be saved." At which time you would do the UNDO and then DON'T set CANCEL for the Form_Unload. If the triggering event was the Before_Update but an UNLOAD wasn't pending, then it might be more of a puzzle as to what to do.
When I run into this problem, what I do is make it impossible to close the form using any of the standard Access methods. What I do is build a CLOSE button that sets a software flag. Then in the Form_Unload, if the flag isn't set, you can't close the form and none of the side effects of closure can occur. The CLOSE button also checks for whether the form is currently dirty and can issue a message warning the user of unsaved data.
I also use a SAVE button and flag so that the Before_Update can know that update event this wasn't due to an implied navigational save. AND you can put validation code under the SAVE button rather than the Before_Update event, so you don't even TRIGGER the save until it passes validation. In essence, this is the philosophy of "get in their way when they make a mistake so they have the chance to fix their mistake." The final piece of that puzzle is, if I am going to make them manually save the record, allow them the option to undo what they have done by adding an UNDO button. That does a Me.Undo on everything so that there is nothing to be saved - which prevents an Access automatic save from occurring.
You CAN just say "continue to fill in blanks to finish the operation" and then when your user tries to save or close the form, eventually the validation code could say "OK, this is acceptable" - at which moment you would do all of the primary and secondary update actions discussed earlier like updating the details and updating the main-table status.
OR you can say "If you are going to close the form in an incomplete state then I will not allow this to be saved." At which time you would do the UNDO and then DON'T set CANCEL for the Form_Unload. If the triggering event was the Before_Update but an UNLOAD wasn't pending, then it might be more of a puzzle as to what to do.
When I run into this problem, what I do is make it impossible to close the form using any of the standard Access methods. What I do is build a CLOSE button that sets a software flag. Then in the Form_Unload, if the flag isn't set, you can't close the form and none of the side effects of closure can occur. The CLOSE button also checks for whether the form is currently dirty and can issue a message warning the user of unsaved data.
I also use a SAVE button and flag so that the Before_Update can know that update event this wasn't due to an implied navigational save. AND you can put validation code under the SAVE button rather than the Before_Update event, so you don't even TRIGGER the save until it passes validation. In essence, this is the philosophy of "get in their way when they make a mistake so they have the chance to fix their mistake." The final piece of that puzzle is, if I am going to make them manually save the record, allow them the option to undo what they have done by adding an UNDO button. That does a Me.Undo on everything so that there is nothing to be saved - which prevents an Access automatic save from occurring.