If your users find it annoying to receive multiple field-error warnings when trying to save a Lotus Notes document, this LotusScript code will allow you to show all the problems or missing fields in a single pop-up.
Just place the code below in the QuerySave event of your form. I prefer to order my checks starting with the fields at the bottom of the form and work my way backwards to the top. That way, the final message shows the errors in order, and can place the cursor in the first field on the screen that has a problem.
Dim workspace As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Set uidoc = workspace.CurrentDocument
Dim item As NotesItem
Dim holder, holder2 As String
Dim Missing, Jumpto As String
'==============================
Jumpto = ""
' field where cursor will end up
'=============================
' sample code to make sure that at least one of two fields is filled in
'=============================
holder = Trim$(source.FieldGetText("USMail"))
' get value of field 1
holder2 = Trim$(source.FieldGetText("eMail"))
' get value of field 2
If (holder1 = "") Then
' if field 1 is empty
If (holder2 = "") Then
' and field 2 is empty
Jumpto = "USMail"
' place cursor here
Missing = "Delivery method (Requirements tab)" + Chr(10) + Missing
' warning message for final pop-up (plus which tab the field is on)
End If
End If
'=============================
' sample code to make sure that an optional field meets required values
'=============================
holder = Trim$(source.FieldGetText("MailNo"))
' get value of field
If Not(holder = "") Then
' if a value exists
If Not(holder = "NA") Then
' and it's not NA
If Not(Isnumeric(holder)) Then
' if not numeric
Jumpto = "MailNo"
' place cursor here
Missing = "Mail number: numeric or NA (Requirements tab)"
+ Chr(10) + Missing
Elseif (Len(holder) > 4) Then
' number, but greater than acceptable length
Jumpto = "MailNo"
' place cursor here
Missing = "Mail number: 4 digits (Requirements tab)"
+ Chr(10) + Missing
End If
End If
End If
'=============================
' sample code to make sure that a required field is present, and that the length is acceptable
'=============================
holder = source.FieldGetText("BlockStartRequest")
' get value of field
If (holder = "") Then
' if missing
Jumpto = "BlockStartRequest"
' place cursor here
Missing = "Block requested by" + Chr(10) + Missing
' warning message for pop-up
Elseif (Len(holder) < 4) Then
' present, but less than acceptable length
Jumpto = "BlockStartRequest"
' place cursor here
Missing = "Block requested by (name, not initials)"
+ Chr(10) + Missing
' warning message for pop-up (and an indicator about how to fix it)
End If
'=============================
' sample code to make sure that a required field is present
'=============================
If ( source.FieldGetText( "BlockCategory" ) = "" ) Then
' if field value is missing (don't bother with holder field if only doing one check)
Jumpto = "BlockCategory"
' place cursor here
Missing = "Category" + Chr(10) + Missing
' warning message for pop-up
End If
'=============================
' we've scanned all relevant fields - if we have any issues,
notify them with a single message box
'=============================
If Not(Missing = "") Then
' if we have a problem, notifiy the user
Messagebox "Please enter/correct the following field(s):"
+ Chr(10) + Chr(10) + Missing, 0 + 48,"Required information"
Call source.GotoField( Jumpto )
' jump to the last field we found with an error
Continue = False
' and stop the QuerySave from completing
End If
Do you have comments on this tip? Let us know.
This tip was submitted to the SearchDomino.com tip library by member Dave Fairchild. Please let others know how useful it is via the rating scale below. Do you have a useful Lotus Notes, Domino, Workplace or WebSphere tip or code snippet to share? Submit it to our monthly tip contest and you could win a prize.