Thanks for your reply donstephen, just to answer your question my button is located within the repeating table, I am however unable to open your sample form as I only have InfoPath 2007 SP3 to work with.
The code is:
Public Sub CTRL151_4_Clicked(ByVal sender As Object, ByVal e As ClickedEventArgs)
Dim secDSNav As XPathNavigator = DataSources("SecondaryTable").CreateNavigator()
'Retrieve the rows of the secondary data source'
Dim rows As XPathNodeIterator = secDSNav.Select( _
"/dfs:myFields/dfs:dataFields/d:SecondaryTable", _
NamespaceManager)
'Loop through the rows of the secondary data source and fill the repeating table '
While rows.MoveNext()
Dim ID As String = rows.Current.SelectSingleNode( _
"@SecondID", NamespaceManager).Value
' Add the item to the repeating table '
AddItem(ID)
End While
' Remove the first empty item from the repeating table '
DeleteFirstEmptyItem()
End Sub
Private Sub AddItem( _
ByVal ID As String)
Dim doc As XmlDocument = New XmlDocument()
Dim group As XmlNode = doc.CreateElement("MainTable", _
NamespaceManager.LookupNamespace("d"))
Dim field As XmlNode = doc.CreateElement("MainID", _
NamespaceManager.LookupNamespace("@"))
Dim node As XmlNode = group.AppendChild(field)
node.InnerText = ID
doc.AppendChild(group)
MainDataSource.CreateNavigator().SelectSingleNode( _
"/dfs:myFields/dfs:dataFields", _
NamespaceManager).AppendChild(doc.DocumentElement.CreateNavigator())
End Sub
Private Sub DeleteFirstEmptyItem()
Dim domNav As XPathNavigator = MainDataSource.CreateNavigator()
Dim itemNav As XPathNavigator = domNav.SelectSingleNode( _
"/dfs:myFields/dfs:dataFields/@MainID[1]", _
NamespaceManager)
If itemNav IsNot Nothing Then
itemNav.DeleteSelf()
End If
End Sub
However my code works when I try to populate custom made Fields and Groups, here is my code:
Public Sub CTRL151_4_Clicked(ByVal sender As Object, ByVal e As ClickedEventArgs)
Dim secDSNav As XPathNavigator = DataSources("SecondaryTable").CreateNavigator()
' Retrieve the rows of the secondary data source
Dim rows As XPathNodeIterator = secDSNav.Select( _
"/dfs:myFields/dfs:dataFields/d:SecondaryTable", _
NamespaceManager)
' Loop through the rows of the secondary data source and fill the repeating table
While rows.MoveNext()
Dim ID As String = rows.Current.SelectSingleNode( _
"@SecondID", NamespaceManager).Value
' Add the item to the repeating table
AddItem(ID)
End While
' Remove the first empty item from the repeating table
DeleteFirstEmptyItem()
End Sub
Private Sub AddItem( _
ByVal ID As String)
Dim doc As XmlDocument = New XmlDocument()
Dim group As XmlNode = doc.CreateElement("group2", _
NamespaceManager.LookupNamespace("my"))
Dim field As XmlNode = doc.CreateElement("MainID", _
NamespaceManager.LookupNamespace("my"))
Dim node As XmlNode = group.AppendChild(field)
node.InnerText = ID
doc.AppendChild(group)
MainDataSource.CreateNavigator().SelectSingleNode( _
"/dfs:myFields/my:group1", _
NamespaceManager).AppendChild(doc.DocumentElement.CreateNavigator())
End Sub
Private Sub DeleteFirstEmptyItem()
Dim domNav As XPathNavigator = MainDataSource.CreateNavigator()
Dim itemNav As XPathNavigator = domNav.SelectSingleNode( _
"/dfs:myFields/my:group1/my:group2/my:MainID[1]", _
NamespaceManager)
If itemNav IsNot Nothing Then
itemNav.DeleteSelf()
End If
End Sub
End Class
But what I really need is to populate my Main Data Connection so that I can Submit all of the ID's.