I am putting code in a querysave event that will not let a user save a document if a duplicate exists. I am trying to do field validation also by saying if a field isn’t 10 digits long then pop up a msgbox and let the user edit the field. Below is the code that does the validation but it closes the form afterwards. How can I get the form to stay open for the user?
Sub Querysave(Source As Notesuidocument, Continue As Variant)
Dim session As New NotesSession
Dim ws As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim doc As NotesDocument
Dim npi As String
Dim ssn As String
Set db = session.CurrentDatabase
Set uidoc = ws.CurrentDocument
Set CheckSaveView = db.GetView("(CheckSave)")
SSN = uidoc.FieldGetText("SSN")
NPI = uidoc.FieldGetText("NPI")
Set doc = CheckSaveView.GetDocumentByKey(SSN)
If Len(NPI) =10 Then
'do nothing
Else
Msgbox "The NPI Number must be ten digits, please correct"
Continue = False
End If
If uidoc.IsNewDoc Then
If Not (doc Is Nothing) Then
'Messagebox "There is a document already, do NOT save"
Call uidoc.FieldSetText("SaveOptions", "0")
Else
End If
End If
SSN = FullTrim(uidoc.FieldGetText(“SSN”)) 'Use Trim if on pre R6 platform
NPI = FullTrim(uidoc.FieldGetText(“NPI”))
and second,
this Call uidoc.FieldSetText(“SaveOptions”, “0”) is redundant and probably won’t work (you can’t FieldSetText on a nondisplayed field) so just use the Continue =False again, that should stop the save.
Sub Querysave(Source As Notesuidocument, Continue As Variant)
Dim session As New NotesSession
Dim doc As NotesDocument
Dim npi As String
Dim ssn As String
Set db = session.CurrentDatabase
Set uidoc = ws.CurrentDocument
Set CheckSaveView = db.GetView("(CheckSave)")
SSN = Source.FieldGetText("SSN")
NPI = Source.FieldGetText("NPI")
Set doc = CheckSaveView.GetDocumentByKey(SSN)
If Len(NPI) =10 Then
'do nothing
Else
Msgbox "The NPI Number must be ten digits, please correct"
Call Source.GotoField("NPI")
Continue = False
Goto fixnpi
End If
If Source.IsNewDoc Then
If Not (doc Is Nothing) Then
'Messagebox “There is a document already, do NOT save”
Call Source.FieldSetText("SaveOptions", "0")
Else
End If
End If