Home › Forums › General XMetaL Discussion › How to stop File – > Close or Window Close functionality when validation fails. › Reply To: How to stop File – > Close or Window Close functionality when validation fails.
Reply to: How to stop File – > Close or Window Close functionality when validation fails.October 18, 2010 at 9:48 pm
You cannot stop a document from closing in the event On_Document_Close as the close process has already begun.
In order to stop a document from closing you will need to override the File > Close action. See “File operations” as I have previously noted.
When you override that action a document will not close unless you specifically tell it to close. In the table for that help topic you will see the APIs you need to call to give you the “default” behavior for the action. If you do not call the API then the default behavior will never occur (and in this case the user will never be able to close a document).
In your case your logic might be something like this:
1) Do validation or whatever else you like to obtain a result of some kind.
2) Create a boolean based on that result.
3) Do an if...then type of check on the boolean. Perhaps something similar to this:
if (bool_allowDocumentToClose = true) then
else (bool_allowDocumentToClose = false) then
Application.Alert("Sridhar says: You cannot close this document because...")