Wednesday, June 15, 2005

OnSaveRequest Event tip

OnSaveRequest Event

Occurs when the save operation is invoked from the Microsoft Office InfoPath 2003 user interface or by using the Save or SaveAs method of the XDocument object in the InfoPath object model.
Function XDocument::OnSaveRequest(ByRef pEvent As SaveEvent)
pEvent Required SaveEvent. A reference to the SaveEvent object.
Remarks
If the ReturnStatus property of the SaveEvent object is set to False, InfoPath cancels the save operation. If an error occurs in the code for the OnSaveRequest event handler, InfoPath ignores the error and relies on the ReturnStatus property of the SaveEvent object. If the ReturnStatus property is not explicitly set, the default value of False is used.
The ReturnStatus property works in conjunction with the IsCancelled property when the InfoPath form is closing. If the document has changes that have not been saved and the user cancels the save operation, the IsCancelled property can be set to True to allow InfoPath to close.
Note This object model member is not supported when the Disable Service Pack features option on the Advanced tab of the Options dialog box in InfoPath is selected or when Microsoft Office 2003 Service Pack 1 or later is not installed. Any form that implements this object model member in its code will generate an error message if it is opened in InfoPath when service pack features are disabled or unavailable.
Example
In the following example, the OnSaveRequest event handler is used to create an XMLHTTP object for transporting the form's underlying XML document:function XDocument::OnSaveRequest(eventObj)
{
// Write the code to be run before saving here.
XDocument.UI.Alert("Begin saving form.");
eventObj.IsCancelled = eventObj.PerformSaveOperation();
// Write the code to be run after saving here.
XDocument.UI.Alert("Form saved.");
eventObj.ReturnStatus = true;
}


I 'd like to add that it is needed a little configuration item so as to that event be fired, because you 'll have the problem that the event is not fired.

You must do some steps:

At Design Mode of your Infopath Form
Go to Tools/Form Options menu
On the Open & Save Tab, On the Save behavior section, check the "Save using custom code" option.

0 Comments:

Post a Comment

<< Home