Closing Without PromptingA couple people have asked, recently, about closing a document without being prompted to save. There are a few different ways to do this.
The first couple are through action buttons, one formula, and one script. Let's go over the formula language one first.
You would think that two @Commands would do the trick:
But this doesn't work in all situations. Specifically, it doesn't work if you have input validation on your form that fails. So this is more generic code:
Check := @If(@IsValid; 0; @Return(0));
The first statement runs through the validation on the form. If all validation formulas succeed, the variable "Check" is set to zero (nothing is done with the value). If any validation fails, the action button formula is stopped from doing anything more. The @IsValid function will actually bring up the validation prompts to the user, so you don't have to worry about that part.
After the validation is successful, the save and close happens and the user isn't prompted to save the document.
If you like working with LotusScript instead of formulas, here is a LotusScript equivalent to the above formula:
Dim ws As New notesUIWorkspace
Dim uiDoc As notesUIDocument
Set uiDoc = ws.currentDocument
On Error Resume Next
On Error Goto 0
If Err <> 0 Then
Err = 0
After getting the current document, we attempt to save it. But we trap for an error. If there was an error saving the document (there would be if validation failed), then clear the global error handler. We clear the value or else it would still be set the next time we attempted to save. If there was not an error saving the document, then we can go ahead and close the window.
The above script is similar to some other script we have posted that checks to see if a document passes validation before proceeding with other code. That script can be found here.
Both of these methods require the user to click on an action button. If the user presses ESC, they are still prompted to save the changes. The only way to prevent this prompt is to automatically save no matter what (or, alternatively, never save no matter what). This is controlled through a field on the form called SaveOptions. This field is a text field and can be computed for display. If set to "0", the document will never be saved. If set to "1", the document will always be saved.
The SaveOptions field can also be computed (determine if this user is able to save the document or not, or determine if it should be saved based on some other criteria). Doing this is outlined in another tip on the Breaking Par web site.