Share via


View3.ExecuteAction method (String, Object)

Executes a Microsoft InfoPath editing command against a form's underlying XML document, based on the data selected in the view.

Namespace:  Microsoft.Office.Interop.InfoPath
Assembly:  Microsoft.Office.Interop.InfoPath (in Microsoft.Office.Interop.InfoPath.dll)

Syntax

'Declaration
Sub ExecuteAction ( _
    bstrAction As String, _
    varXmlToEdit As Object _
)
'Usage
Dim instance As View3
Dim bstrAction As String
Dim varXmlToEdit As Object

instance.ExecuteAction(bstrAction, varXmlToEdit)
void ExecuteAction(
    string bstrAction,
    Object varXmlToEdit
)

Parameters

  • bstrAction
    Type: System.String

    The name of the editing action to perform.

  • varXmlToEdit
    Type: System.Object

    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.

Implements

View2.ExecuteAction(String, Object)

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).

It is possible to first set the selection context by using the SelectNodes(IXMLDOMNode, Object, Object) method or SelectText(IXMLDOMNode, Object) method, then call 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.

  • The following is a table of parameter combinations that can be used with the ExecuteAction method.

Combination

Description

"Copy"

Copies the selected data to the clipboard.

"Paste"

Copies data from the clipboard to the insertion point.

"Cut"

Removes the selected data and copies it to the clipboard.

"Delete"

Deletes the selected data.

"xCollection::insert", "xmlToEdit"

Inserts data based on the selected context using the xCollection editing component. If current selection is within a container of the xCollection, specified by its xmlToEdit element in the .xsf, then the fragmentToInsert element data is appended within that container.

"xCollection::insertBefore", "xmlToEdit"

Inserts data before the selected context using the xCollection editing component. If current selection is within an item of the xCollection, as specified by its xmlToEdit element in the .xsf, then the fragmentToInsert element data is inserted before that item.

"xCollection::insertAfter", "xmlToEdit"

Inserts data after the selected context using the xCollection editing component. If current selection is within an item of the xCollection, as specified by its xmlToEdit element in the .xsf, then the fragmentToInsert element data is inserted after that item.

"xCollection::remove", "xmlToEdit"

Deletes data from the selected context using the xCollection editing component. If current selection is within an item of the xCollection, as specified by its xmlToEdit element in the .xsf, then that item is deleted.

"xCollection::removeAll", "xmlToEdit"

Deletes all data contained within the selected context using the xCollection editing component. If current selection is within a container of the xCollection, as specified by the xmlToEdit element in the .xsf, then this action deletes all the items within that container.

"xReplace::replace", "xmlToEdit"

Replaces the data in the selected context using the xReplace editing component. If current selection is within an item of the xReplace, as specified by its xmlToEdit element in the .xsf, then that item is replaced by the fragmentToInsert element data.

"xOptional::insert", "xmlToEdit"

Inserts data based on the selected context using the xOptional editing component. If current selection is within an container of the xOptional, as specified by its xmlToEdit element in the .xsf, then the fragmentToInsert element data is appended within that container.

"xOptional::remove", "xmlToEdit"

Deletes data from the selected context using the xOptional editing component. If current selection is within an item of the xOptional, as specified by its xmlToEdit element in the .xsf, then that item is deleted.

Note   In some cases, calling the ExecuteAction method from the OnClick 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.

See also

Reference

View3 interface

View3 members

ExecuteAction overload

Microsoft.Office.Interop.InfoPath namespace