FieldGetText document closing

I have the following code in the QuerySave event. I get the messagebox to pop up, then click OK and the document closees completely instead of moving to the next IF statement. Where do I put the Call uidoc.close or do I not need it?

Sub Querysave(Source As Notesuidocument, Continue As Variant)

Dim Session As New NotesSession

Dim ws As New NotesUIWorkspace

Dim db As NotesDatabase

Dim uidoc As NotesUIDocument

Dim doc As NotesDocument



Set db = session.CurrentDatabase

Set uidoc = ws.CurrentDocument

Call uidoc.refresh



'check for required fields

If (uidoc.FieldGetText("RequestedBy")="") Then

	Msgbox("Requested By is required.")

	uidoc.GoToField("RequestedBy")

	Exit Sub

End If



If (uidoc.FieldGetText("Unit")="") Then

	Msgbox("The Unit is required.")

	uidoc.GoToField("Unit")

	Exit Sub

End If



If (uidoc.FieldGetText("FObj")="") Then

	Msgbox("The featured objective is required.")

	uidoc.GoToField("FObj")

	Exit Sub

End If



If (uidoc.FieldGetText("CollegeUnit")="Select College") Then

	Msgbox("The unit, campus, college the fund supports is required.")

	uidoc.GoToField("CollegeUnit")

	Exit Sub

End If



If (uidoc.FieldGetText("Title")="") Then

	Msgbox("The name of the allocation fund is required.")

	uidoc.GoToField("Title")

	Exit Sub

End If



If (uidoc.FieldGetText("Guideline")="") Then

	Msgbox("Will fund have a Guideline is required.")

	uidoc.GoToField("Guideline")

	Exit Sub

End If



Call uidoc.save

Call uidoc.close

End Sub

Subject: FieldGetText document closing

Not sure exactly why the document closes, but I do see a few things in your code that aren’t quite “right”…

First, you are in the QuerySave Event which acts on the currently open uidoc, so you do not need to declare and set uidoc. It is already setup in the event as “source”

If (source.FieldGetText(“RequestedBy”)=“”) Then…

You also don’t need to declare your session, workspace or document for this code (unless you are planning to use those classes later).

Second, you can’t call the save method of the uidoc within a QuerySave event. You will get a recursive error. Search for “Event sequencing” in the help to get a better idea of how these events work.

Third, exiting a QuerySave sub will not prevent the document from saving, Notes will proceed to save the document , then run the PostSave Event. You need to halt excecution of the QuerySave, by using: Continue=False. Continue is a Variant declared in the event.

Finally, I don’t recommend using the close event here. It seems like strange functionality, if a user just wants to save a document. If you want to use a “Save and Close” type button, I recommend using Field validations to control the operation.

So try something like this:

Sub Querysave(Source As Notesuidocument, Continue As Variant)

If (source.FieldGetText(“RequestedBy”)=“”) Then

Msgbox(“Requested By is required.”)

uidoc.GoToField(“RequestedBy”)

Continue=False

Exit Sub

End Sub

Good Luck!

Subject: RE: FieldGetText document closing

In addition to Steve’s comments, so the poor user doesn’t have to go through a bunch of prompts showing all the fields they missed I normally do this:

errmsg = “”

if (source.FieldGetText(“RequestedBy”)=“”) Then

. . errmsg := errmsg + “Requested By is required.” + Chr(13)

End If

if (source.FieldGetText(“X”)=“”) Then

. . errmsg := errmsg + “X is required.” + Chr(13)

End If

if (source.FieldGetText(“Y”)=“”) Then

. . errmsg := errmsg + “Y is required.” + Chr(13)

End If

if errmsg<>“” then

. . errmsg = "The following required fields are blank: " + Chr(13) + errmsg

. . Msgbox(errmsg)

. . continue = False

End if

To then go one step futher, I actually have a field on the form look-up all the required fields off a keyword/Profile document … Then you can just do it via a loop

Set doc = source.document

errmsg = “”

For x=0 to ubound(doc.nonblankfields)

. . if trim(source.FieldGetText(doc.nonblankfields(x))) = “” then

. . . . errnsg := errmsg + doc.nonblankfields(x) + " is required and is empty." + chr(13)

. . End if

Next

if errmsg<>“” then

errmsg = "The following required fields are blank: " + Chr(13) + errmsg

Msgbox(errmsg)

continue = False

End if

Normally then create a cross reference table to look up the “field name” to match up and return the “label” so the user gets a message like “Requested By is required and is empty” vs “RequestedBy is required and isempty” in particular if your variable names aren’t very meaningful.

Set doc = source.document

errmsg = “”

For x=0 to ubound(doc.nonblankfields)

. . if trim(source.FieldGetText(doc.nonblankfields(x))) = “” then

. . . . errnsg := errmsg + TranslateFieldName(doc.nonblankfields(x)) + " is required and is empty." + chr(13)

. . End if

Next

if errmsg<>“” then

errmsg = "The following required fields are blank: " + Chr(13) + errmsg

Msgbox(errmsg)

continue = False

End if

Subject: RE: FieldGetText document closing

Thank you both. The check is now working properly, but now my e-mail message isn’t being generated. I was getting prompted if I want to save the document after each statement, so I found (in this forum) to change my Save & Exit button to: @If( @Command([FileSave]); @Command([FileCloseWindow]); “”)

rather than:

@Command([FileSave]);

@Command([FileCloseWindow])

Now, the check is working and saving the document, but not sending my e-mail message that is in the save and exit button. Can I turn my @Command into script to include in the QuerySave event for the e-mail message? Here is a piece of that code:

tmpEmail:=@If(ACode!=“” & ACodeNotification = “”; “The allocation code / or update you requested on " + @Text(CreateDate) + " has been completed.” + @NewLine + @NewLine + "Allocation Code: " + ACode + @NewLine + "Description: " + Purpose + @NewLine + "Featured Objective: " + FObj + @NewLine + @NewLine + “You may review the form / criteria by going into the Lotus Notes Allocation Code Request database.”; “unknown”);

Subject: RE: FieldGetText document closing

Quick answer to your question is, YES.

AS I don’t trust my memory, there should be lots of examples on this form… for example.

Just search for the word memo.

A bit of advice make sure you have line in the script after the emailDoc.Send like

Set emailDoc = Nothing so you don’t save a copy of the memo in your database (no need to keep things you don’t need).

= = = = = =

Your code doesn’t seem to generate any e-mail?

tmpEmail:= @If(ACode!=“” & ACodeNotification = “”;

. . . . “The allocation code / or update you requested on " + @Text(CreateDate) + " has been completed.” +

. . . . @NewLine + @NewLine +

. . . . "Allocation Code: " + ACode + @NewLine +

. . . . "Description: " + Purpose + @NewLine +

. . . . "Featured Objective: " + FObj + @NewLine + @NewLine +

. . . . “You may review the form / criteria by going into the Lotus Notes Allocation Code Request database.”;

. . . .“unknown”

);

I’m guesing there must be a SendTo Field on the form and the form propties have something like this set?