LS validation probs

In the QuerySave event of my form a validation takes place, I get kicked back out to the view. Can someone tell me what I am doing wrong or what I am missing because this is not working and the document keeps getting saved when it should not if there is a validation msg. By the way is there a way that only one msg (one that includes all the validation msgs in one list) be presented on the screen and then return the user to the appropriate field (I have never done that)?

Thanks,

Dan

Here is what I have:

Sub Querysave(Source As Notesuidocument, Continue As Variant)

Dim s As New NotesSession

Dim db As NotesDatabase

Dim w As New NotesUIWorkspace

Dim doc As NotesDocument

Dim item As NotesItem

Dim dt As NotesDateTime

Set db = s.CurrentDatabase

Set doc = Source.Document

bSaved = False

'Dont let it save until continue = true

Continue = False

‘XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

'validate entries

If doc.Status(0) = “” And doc.VisitorName(0) = “” Then

Msgbox “Missing entry for Visitor Name!”, MB_ICONSTOP, “Save & Close”

’source.GoToField (" VisitorName")

Continue = False

Else

If doc.Status(0) = “New/Nouveau” And doc.NewVisitorName(0) = “” Then

Msgbox “Missing entry for Visitor Name!”, MB_ICONSTOP, “Save & Close”

’source.GoToField (" NewVisitorName")

Continue = False

End If

End If

If doc.Status(0) = “New/Nouveau” And doc.NewCompanyName(0) = “” Then

Msgbox “Missing entry for Company Name!”, MB_ICONSTOP, “Save & Close”

’source.GoToField (" CompanyName")

Continue = False

End If

If doc.Names(0) = “” Then

Msgbox “Missing entry for Person visited!”, MB_ICONSTOP, “Save & Close”

’source.GoToField (" Names")

Continue = False

End If

If doc.Region(0) = “” Then

Msgbox “Missing entry for Region!”, MB_ICONSTOP, “Save & Close”

’source.GoToField (“Region”)

Continue = False

End If

If doc.Location(0) = “” Then

Msgbox “Missing entry for Location!”, MB_ICONSTOP, “Save & Close”

’source.GoToField (“Location”)

Continue = False

End If

‘XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Set dt = New NotesDateTime(“1/1/1980”)

Call dt.SetNow()

Set item = doc.ReplaceItemValue( “ModifyDate”, dt.LSLocalTime)

Set item = doc.ReplaceItemValue( “Modifier”, s.CommonUserName)

'set the date fields so they have the time after them

Set dt = New NotesDateTime(doc.AwayFrom(0))

Set item = doc.ReplaceItemValue( “AwayFrom”, dt.LSLocalTime)

Set dt = New NotesDateTime(doc.BackOn(0))

Set item = doc.ReplaceItemValue( “BackOn”, dt.LSLocalTime)

Set dt = New NotesDateTime(doc.AwayFromTime(0))

Set item = doc.ReplaceItemValue( “AwayFromTime”, dt.TimeOnly)

Set dt = New NotesDateTime(doc.BackOnTime(0))

Set item = doc.ReplaceItemValue( “BackOnTime”, dt.TimeOnly)

'all OK

Continue = True

bSaved = True

'==============================================================

'Msgbox( "Strarting Agent - NewVisitorProfile_Notes ")

’ Handle New Visitor Request

'If the Status field is = “New” then create a separate visitor profile document

'Msgbox( “Break 1”)

If ( doc.Status(0) = “New/Nouveau” ) Then

FName$ = doc.FName(0)

LName$ = doc.LName(0)

CompanyName$ = doc.CompanyName(0)

CompanyAddress$ = doc.CompanyAddress(0)

CompanyCity$ = doc.CompanyCity(0)

CompanyProvState$ = doc.CompanyProvState(0)

CompanyPostalCode$ = doc.CompanyPostalCode(0)

CompanyPhone$ = doc.CompanyPhone(0)

CompanyFax$ = doc.CompanyFax(0)

CompanyCell$ = doc.CompanyCell(0)

Dim profiledoc As NotesDocument

Set profiledoc = db.CreateDocument

'Msgbox( “Break 2”)

'Pass the values from the current web document to the Visitor Information Profile form and save it

profiledoc.Form = “Visitor Information”

profiledoc.FirstName = FName$

profiledoc.LastName = LName$

profiledoc.CompanyName = CompanyName$

profiledoc.MainAddress = CompanyAddress$

profiledoc.City = CompanyCity$

profiledoc.Province = CompanyProvState$

profiledoc.PostCode = CompanyPostalCode$

profiledoc.PhoneNum = CompanyPhone$

profiledoc.FaxNum = CompanyFax$

profiledoc.CellNum = CompanyCell$

'Msgbox( “Break 3”)

Call profiledoc.Save(True,True)

End If

'Msgbox( “Ending Agent - NewVisitorProfile”)

'===================================================================

End Sub

Subject: LS validation probs

You’ll want to add “exit sub” after your error msgs so that it does not keep processing. What is happening is that it sets it to false, but keeps processing the code further when it reaches a “Continue = true” and allows it to be saved.

As for making one msg, you could use a string variable to keep a list of all the errors, then if it’s length is > 0, msgbox it and exit.

–Rob

Subject: First off, I suspect this would be easier in Form Input Validation formulas, but…

Continue = False‘XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

'validate entries

If doc.Status(0) = “” And doc.VisitorName(0) = “” Then

Msgbox “Missing entry for Visitor Name!”, MB_ICONSTOP, “Save & Close”

source.GoToField (" VisitorName")

Exit Sub

End If

If doc.Status(0) = “New/Nouveau” And doc.NewVisitorName(0) = “” Then

Msgbox “Missing entry for Visitor Name!”, MB_ICONSTOP, “Save & Close”

source.GoToField (" NewVisitorName")

Exit Sub

End If

If doc.Status(0) = “New/Nouveau” And doc.NewCompanyName(0) = “” Then

Msgbox “Missing entry for Company Name!”, MB_ICONSTOP, “Save & Close”

source.GoToField (" CompanyName")

Exit Sub

End If

Subject: RE: First off, I suspect this would be easier in Form Input Validation formulas, but…

Thanks Bill,I tried your suggstionwith the “Exit Sub” code however when the validation kicks in the Exit Sub kicks me out of the document entirely (this time without saving the document thankfully). What I would like to see happen is if the validation notices that the field is empty, to simply go back to the current document. Is this possible?

Thanks,

Dan

Subject: RE: First off, I suspect this would be easier in Form Input Validation formulas, but…

As Bill noted, that’s what the Formula Language Input Validation events are for. Having taken a look at your previous thread, it seems that everyone failed to notice that you weren’t using @Failure to halt the save and prompt the user.

Subject: RE: First off, I suspect this would be easier in Form Input Validation formulas, but…

Thanks for your insight Stan. HOWEVER, when I tried that it kept throwing back the failure msg in the field and when I would select the proper name from the dropdown list it would return a number “1” in the same field. Can you explain why this is happening?

Thanks,

Dan

Subject: RE: First off, I suspect this would be easier in Form Input Validation formulas, but…

Sounds like the code was in the Input Translation event, Dan – @Success would mean “use the legal representaion of True instead of the input value”, which would be “1” in a text field. Same thing happens with the message component of @Failure.

You won’t have been the first person to put the code in the wrong event, especially if you were counting on the selected event to remain the same moving from field to foeld. Sometimes it does, sometimes it doesn’t.

Subject: RE: First off, I suspect this would be easier in Form Input Validation formulas, but…

How stupid of me !!! MANY THANKS Stan !!!

Dan