OnSwitchView Event

Microsoft Office InfoPath

Occurs after a view in a Microsoft Office InfoPath 2003 form has been successfully switched.

Function XDocument::OnSwitchView(ByRef pEvent As DocEvent)

pEvent Required DocEvent. A reference to the DocEvent object.

Remarks

This event handler does not allow users to cancel an operation.

Note  The OnSwitchView event also occurs when a form is first opened.

Example

In the following example from the Events developer sample form, the OnSwitchView event handler is used to check the name of the current view. If the view has the name "Archive Customer," data is added to the form's underlying XML document.

function XDocument::OnSwitchView(eventObj)
{
   var oDate = new Date();

   if (XDocument.View.Name == "Archive Customer")
   {
      var oNotesNode = XDocument.DOM.
         selectSingleNode("/Customers/CustomerInfo/Notes");
      var oDivNode = XDocument.DOM.
         createNode(1, "div", "http://www.w3.org/1999/xhtml");

      oDivNode.text = "Note recorded " + oDate.toString();
      oNotesNode.appendChild(oDivNode);
   }
}