InfoPath – Confirm and Close

One glaring shortcoming of InfoPath is an option that allows you to tell InfoPath to close after a form is submitted. There is the option to close the form, but not close the application. So, here’s the code to make it happen.

Put this in the Code of a Submit button.

Note: Be sure to leave the function CTRL19_5::OnClick(eventObj) (your CTRL number will be different) line alone and place the following between the two {}:

if (XDocument.Errors.Count > 0) 
{
XDocument.UI.Alert("Required information is missing as indicated by the red asterisk(s).") ; 
return; 
} 
try 
{ XDocument.Submit() Application.ActiveWindow.Close(true); } 
catch(e) 
{ XDocument.UI.Alert(e.description); }

The first part of the code checks to see if there are any required fields that have no value. If there are, the text displayed in teal is presented to the user and control returns to InfoPath. If no errors are found, the Submit is attempted. If an error or another kinds is found, the error message is displayed. Be sure to turn on Submit options in the Forms Options dialog.

Tagged on:

Leave a Reply

Your email address will not be published. Required fields are marked *