Hi Jimmy, hoping you can help me out!
I have used the info in this post to create some code that inserts a new row in a repeating table and sets the value of a field in the new (last) row of that table on the click of a button. The code works brilliantly on one view of my form and works exactly as it should so I've tried to replicate the code to perform the exact same function on a differnt view of the form, using a different button.
Unfortunately it doens't seem to be working - I'm getting the following error when debugging the code:
InfoPath has encountered an error. The operation failed.
The form's code contains an error.
The following call in the form's code failed: View.ExecuteAction
Unknown name.
I've pasted the code below and would really appreciate it if you could take a look and let me know what's going wrong - I'm not a developer and not really have any code experience other than hacking at samples I've nicked off of here! One thing to note is that the repeating table being updated is on an enitrely separate view to both of the buttons that are firing the code. On one of the posts I read it said that you need to have a copy of the repeating table on the same view as the button to fire the code or the code won't work so I have copies of the repeating table on both views that are hidden via conditional formatting.
Also of note is the fact that if I remove the second set of code, the first button works correctly (e.g. inserts a new row, sets the field value, submits and closes the form); if I remove the first portion of code and leave the second portion however, I still get the same error!
Hopefully this all makes sense!
Imports Microsoft.Office.InfoPath
Imports System
Imports System.Windows.Forms
Imports System.Xml
Imports System.Xml.XPath
Imports mshtml
Namespace Purchase_Order_Form_V2._0
Public Class FormCode
' Member variables are not supported in browser-enabled forms.
' Instead, write and read these values from the FormState
' dictionary using code such as the following:
'
' Private Property _memberVariable() As Object
' Get
' _memberVariable = FormState("_memberVariable")
' End Get
' Set
' FormState("_memberVariable") = value
' End Set
' End Property
' NOTE: The following procedure is required by Microsoft InfoPath.
' It can be modified using Microsoft InfoPath.
Private Sub InternalStartup(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Startup
AddHandler DirectCast(EventManager.ControlEvents("CTRL126"), ButtonEvent).Clicked, AddressOf CTRL126_Clicked
AddHandler DirectCast(EventManager.ControlEvents("CTRL201"), ButtonEvent).Clicked, AddressOf CTRL201_Clicked
End Sub
Public Sub CTRL126_Clicked(ByVal sender As Object, ByVal e As ClickedEventArgs)
CurrentView.ExecuteAction(ActionType.XCollectionInsert, "PurchaseOrderStatusGroup_300")
Dim PurchaseOrderStatus As XPathNavigator = _
Me.MainDataSource.CreateNavigator().SelectSingleNode( _
"/my:PurchaseOrder/my:FinanceSummary/my:PurchaseOrderStatusGroup[last()]/my:POStatus", NamespaceManager)
PurchaseOrderStatus.SetValue("PO Cancelled by Requestor")
Dim fileSubmit As FileSubmitConnection = CType(Me.DataConnections("SharePoint Library Submit"), Microsoft.Office.InfoPath.FileSubmitConnection)
fileSubmit.Execute()
Me.Close()
End Sub
Public Sub CTRL201_Clicked(ByVal sender As Object, ByVal e As ClickedEventArgs)
CurrentView.ExecuteAction(ActionType.XCollectionInsert, "PurchaseOrderStatusGroup_328")
Dim PurchaseOrderStatus As XPathNavigator = _
Me.MainDataSource.CreateNavigator().SelectSingleNode( _
"/my:PurchaseOrder/my:FinanceSummary/my:PurchaseOrderStatusGroup[last()]/my:POStatus", NamespaceManager)
PurchaseOrderStatus.SetValue("PO Cancelled by Requestor")
Dim fileSubmit As FileSubmitConnection = CType(Me.DataConnections("SharePoint Library Submit"), Microsoft.Office.InfoPath.FileSubmitConnection)
fileSubmit.Execute()
Me.Close()
End Sub
End Class
End Namespace