ExecuteAction Method

Microsoft Office InfoPath

Show All Show All

ExecuteAction Method

Executes a Microsoft Office InfoPath 2003 editing command against a form's underlying XML document, based on the data selected in the view that is associated with the View object.

expression.ExecuteAction(ByVal bstrAction As String, [ByVal varXmlToEdit As Variant])

expression    Required. An expression that returns a reference to the View object.

bstrAction Required String. The name of the editing action to perform.

varXmlToEdit Optional Variant. The name of the field or group to which to apply the editing action. This is equivalent to the value of the name attribute in the xmlToEdit element of the form definition (.xsf) file.

Security Level

2: Can be accessed only by forms running in the same domain as the currently open form, or by forms that have been granted cross-domain permissions.

Remarks

The ExecuteAction method is used to programmatically perform built-in InfoPath editing actions against a form's underlying XML document, based on the selected context in a view.

The action that is executed will be the same action that would be used when clicking on an equivalent menu or toolbar button; namely one for which the button element in the .xsf file has corresponding xmlToEdit and action attributes. As with using a button, the action will be based on current selection: it will act on the selected context (and in the case where the selection would lead the button to be disabled, then the ExecuteAction method will have no effect).

Note  It is possible with scripting code to first set the selection context by using the SelectNodes or SelectText methods of the View object, then calling the ExecuteAction method to act on that context.

The ExecuteAction method will return an error for the following reasons:

  • The bstrAction parameter does not contain a valid editing component name.
  • The varXmlToEdit parameter does not match an editing component that is defined in the view.
  • The varXmlToEdit parameter is required for a specific editing action.
  • The editing action is not applicable to the selected context.

ShowValid parameter combinations

Note  In some cases, calling the ExecuteAction method from the OnClick event for a button in a view may cause an error. This is because the selected context changes to the button when the button is clicked. In this case, it is better to use a button (or link) on a custom task pane, toolbar, or menu to call the ExecuteAction method.

Example

In the following example, the ExecuteAction method of the View object is used to delete selected data and place it on the clipboard:

    XDocument.View.ExecuteAction("Cut");
  

In the following example, the ExecuteAction method of the View object is used to insert data using the xCollection editing component, based on the selected context:

    XDocument.View.ExecuteAction("xCollection::insert", "group1_1");