OnVersionUpgrade Event

Occurs when the version number of a Microsoft Office InfoPath 2003 form being opened is older than the version number of the form template on which it is based.

Function XDocument::OnVersionUpgrade(ByRef pEvent As VersionUpgradeEvent)

pEventRequired VersionUpgradeEvent. A reference to the VersionUpgradeEvent object.

Remarks

This event handler allows users to cancel an operation.

During the OnVersionUpgrade event, the form's underlying XML document is placed in read-only mode, and it is not validated against the form's associated XML Schema. If the ReturnStatus property of the VersionUpgradeEvent object is set to False, InfoPath cancels the opening of the form. If an error occurs in the scripting code for the OnVersionUpgrade event handler, InfoPath ignores it and relies on the ReturnStatus property of the VersionUpgradeEvent object. If the ReturnStatus property is not explicitly set, the default value of True is used.

Example

In the following example from the Events developer sample form, the OnVersionUpgrade event handler is used to determine whether the form with the incorrect older version number contains an EmailAddress element. If it does not, one is added.

function XDocument::OnVersionUpgrade(eventObj)
{
   if (!XDocument.DOM.selectSingleNode("/Customers/CustomerInfo/EmailAddress"))
   {
      try
      {
         // Create the new element.
         var objItemNode = XDocument.DOM.selectSingleNode("/Customers/CustomerInfo")
            .ownerDocument.createElement("EmailAddress");

         // Add the new <item> element to the XML document as a
         // child of the <order> element.
         XDocument.DOM.selectSingleNode("/Customers/CustomerInfo")
            .appendChild(objItemNode);
         eventObj.ReturnStatus=true;
      }
      catch(ex)
      {
         XDocument.UI.Alert("There was an error inserting the " +
            "<EmailAddress> node.\nDescription: " + ex.description);
         eventObj.ReturnStatus=false;
      }
   }
}

Applies to | XDocument Object