I have a form. The form fields are validated in the querysave event. The validation goes like this. I have some fields to be validated for its presence during save. i.e., when i click a check box and dont enter the details in its field, it should show a error message box while saving. The validation works fine for a new document. My question is
- how to make it work for both new document and edit mode?
- The error message is not getting displayed the second time when i click on save.i.e., when i click ok in the messagebox, dont enter data and click save, its getting saved. how to make it check for validation everytime when clicked on save.
Kindly help me. Please dont mind if my questions are obvious and simple because i m a fresher. Thanks in advance.
The script goes below,
The first part calculating ref num for new docs and secong part validating fields,
Sub Querysave(Source As Notesuidocument, Continue As Variant)
Dim w As New notesuiworkspace
Dim uidoc As notesuidocument
Set uidoc = w.CurrentDocument
Dim SESS As New NotesSession
Dim Doc As NotesDocument
Dim RefView As NotesView
Dim DB As NotesDatabase
Dim RefDoc As NotesDocument
Set DB = SESS.CurrentDatabase
Set Doc = uidoc.Document
Set RefView = DB.GetView("System\AutoNo")
If uidoc.IsNewDoc = True Then
Financial_year = Clng(Right$(Cstr(Year(Now)),3)) + 104
If Month(Now) >= 4 Then Financial_year = Financial_year + 1
Application = "ST"
DefKey$ = Cstr(Financial_year)
DefNo& = 0
Set RefDoc = RefView.GetDocumentByKey(DefKey$ , True)
If Not(RefDoc Is Nothing) Then DefNo& = Clng(Right$(RefDoc.SETTLEMENT_NO(0),5))
DefNo& = DefNo& + 1
RefNo$ = (Application + DefKey$) & "-" & Right$("00000" & Cstr(DefNo&) ,5)
Doc.SETTLEMENT_NO= RefNo$
Doc.FinFlag="Finish"
Call SESS.SetEnvironmentVar("ENV_SETT",Right$("00000" & Cstr(DefNo&) ,5))
Call uidoc.Refresh
Else
Exit Sub
End If
get_ex_rate
get_cv_local
set_flag
Dim answer2 As Integer
answer2% = Msgbox("Do you want to save this document?", 1, "Save")
If answer2 = 1 Then
Petro$= uidoc.FieldGetText("Park_Petro_Car")
Vehicle$= uidoc.FieldGetText("Vehicle_No")
Gifts$ = uidoc.FieldGetText("Gifts")
Gifts_Ent$ = uidoc.FieldGetText("Gifts_Ent")
Medical$ = uidoc.FieldGetText("Medical")
Medical_Fee$ = uidoc.FieldGetText("Medical_Fee")
Others$= uidoc.FieldGetText("Others")
OS$= uidoc.FieldGetText("Others_Specify")
Taxi$ = uidoc.FieldGetText("Taxi")
Taxi_Fee$ = uidoc.FieldGetText("Taxi_Fee")
If Petro$ <> "" And Vehicle$ = "" Then
Msgbox "Please enter Vehicle No" , 16, "Vehicle No"
Else
If Gifts$ <> "" And Gifts_Ent$ = "" Then
Msgbox "Please enter Guest/Co.Name" , 16, "Guest/Co.Name"
Else
If Medical$ <> "" And Medical_Fee$ = "" Then
Msgbox "Please enter Medical_Fee" , 16, "Medical_Fee"
Else
If Taxi$ <> "" And Taxi_Fee$ = "" Then
Msgbox "Please enter Taxi Fee" , 16, "Taxi Fee"
Else
If Others$ <> "" And OS$ = "" Then
Msgbox "Please enter Others(Specify)" , 16, "Others (Specify)"
End If
End If
End If
End If
End If
End If
If answer2 = 2 Then
continue=False
Exit Sub
End If
uidoc.Refresh
'uidoc.close
End Sub
Remove the Else from your first IF Statement, otherwise the validation only runs once, when IsNewDoc returns True, once the doc has been saved once it will return False and your QuerySave Subroutine exits.
ELSE
Exit Sub <– remove this, your validation code only runs once per document.
End IF