API
@-Formulas
JavaScript
LotusScript
Reg Exp
Web Design
Notes Client
XPages
 
Prevent Validation Errors When F9 Is Pressed
There's always the trouble with validation formulas executing when you don't want them to execute. For example, if you have a radio button set to "Refresh Fields On Keyword Change", then validation formulas will execute when the value changes and your users will get prompted with their errors. This would be a case where you don't want the users to be prompted.

One thing you can do is use the @IsDocBeingRecalculated function in your validation formulas to prevent the validation from happening:
@If(@IsDocBeingRecalculated; @Success; ... (rest of validation formula) ...)

For example, let's say we want to check the field "Untitled" for a blank value:
@If(@IsDocBeingRecalculated; @Success; Untitled = ""; @Failure("Please fill out this field"); @Success)

If you do this, then every time you refresh the document (the user presses F9, a keyword field changes, or you call uiDoc.Refresh in a script, as outlined in this document), then the validation will not cause any errors.

That's all well and good, but what if you want to find out if a form is valid before you write it to disk? Well, the @IsValid formula runs through validation and returns @True if the form passes validation, but all that does is refresh the document - which would pass validation with all the new functions.

If you're working with LotusScript, there's a way you can check the document before saving. First, use the same validation formulas outlined above. Next, your LotusScript action button can make an attempt at saving the document and see if the validation fails:
Dim ws As New notesUIWorkspace
Dim uiDoc As notesUIDocument
Set uiDoc = ws.currentDocument
On Error Resume Next
Call uiDoc.Save
On Error Goto 0
If Err <> 0 Then
   Err = 0
   Exit Sub
End If
' ... Continue with your code ...

Again, this just expands on the same ideas as the other tip and traps for an error, tries to save the document (the other tip tries to refresh), and exits if there was an error trying to save.

Note that if there isn't an error, the document is written to disk. That may or may not be important to your code. For example, you may want to check to see document would save, then set some fields, then actually do the save. In that case you would end up with 2 saves, unless you read on to the next page...

Page 1 of 2