Hi, I'm trying to load data into two repeating tables onload. The first one works fine but the second one bombs out on the second pass. Here is the error:
System.NullReferenceException
Object reference not set to an instance of an object.
at InfoPathProject1.InfoPathProject1.State()
at InfoPathProject1.InfoPathProject1.OnLoad(DocReturnEvent e)
at Microsoft.Office.Interop.InfoPath.SemiTrust._XDocumentEventSink2_SinkHelper.OnLoad(DocReturnEvent pEvent)
Here is my code:
Sub Federal()
'Start insert Federal waste codes**********************
Dim dataDOM As DOMDocument50 = thisXDocument.DataObjects("FederalWasteCodes").DOM
dataDOM.setProperty("SelectionNamespaces", "xmlns:dfs=""http://schemas.microsoft.com/office/infopath/2003/dataFormSolution"" xmlns:my=""http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-12-12T22-07-01"" ")
Dim numRows As Integer = thisXDocument.GetDOM("FederalWasteCodes").selectNodes("/dfs:myFields/dfs:dataFields/dfs:FederalWasteCodes").length()
'MsgBox(numRows, MsgBoxStyle.Critical)
Dim oParentNode As IXMLDOMNode
oParentNode = thisXDocument.DOM.selectSingleNode("/my:myFields")
Dim strFields As String
strFields = "<my:CodeConcat xmlns:my='http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-11-01T00:12:07'><my:Federal/></my:CodeConcat>"
Dim domXMLNode As IXMLDOMDocument
domXMLNode = thisXDocument.CreateDOM()
domXMLNode.async = False
domXMLNode.loadXML(strFields)
Dim i As Integer
For i = 1 To numRows
Dim Code As String = thisXDocument.GetDOM("FederalWasteCodes").selectSingleNode("/dfs:myFields/dfs:dataFields/dfs:FederalWasteCodes[" & i & "]/@Code").text
Dim sName As String = thisXDocument.GetDOM("FederalWasteCodes").selectSingleNode("/dfs:myFields/dfs:dataFields/dfs:FederalWasteCodes[" & i & "]/@Short_name").text
'MsgBox(Code, MsgBoxStyle.Critical)
thisXDocument.DOM.selectSingleNode("/my:myFields/my:CodeConcat[" & i & "]/my:Federal").text = Code + ", " + sName
If i <> numRows Then
oParentNode.appendChild(domXMLNode.documentElement.cloneNode(True))
Else
End If
Next
'End insert Federal waste codes***************
End Sub
Sub State()
'Start insert State waste codes****************
Dim dataDOM2 As DOMDocument50 = thisXDocument.DataObjects("CalWasteCodes").DOM
dataDOM2.setProperty("SelectionNamespaces", "xmlns:dfs=""http://schemas.microsoft.com/office/infopath/2003/dataFormSolution"" xmlns:my=""http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-12-12T22-07-01"" ")
Dim numRows2 As Integer = thisXDocument.GetDOM("CalWasteCodes").selectNodes("/dfs:myFields/dfs:dataFields/dfs:CalWasteCodes").length()
'MsgBox(numRows2, MsgBoxStyle.Critical)
Dim oParentNode2 As IXMLDOMNode
oParentNode2 = thisXDocument.DOM.selectSingleNode("/my:myFields")
Dim strFields2 As String
strFields2 = "<my:CodeConcat xmlns:my='http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-11-01T00:12:07'><my:State/></my:CodeConcat>"
Dim domXMLNode2 As IXMLDOMDocument
domXMLNode2 = thisXDocument.CreateDOM()
domXMLNode2.async = False
domXMLNode2.loadXML(strFields2)
Dim iState As Integer
For iState = 1 To numRows2
Dim Code2 As String = thisXDocument.GetDOM("CalWasteCodes").selectSingleNode("/dfs:myFields/dfs:dataFields/dfs:CalWasteCodes[" & iState & "]/@Code").text
'MsgBox(Code2, MsgBoxStyle.Critical)
Dim sName2 As String = thisXDocument.GetDOM("CalWasteCodes").selectSingleNode("/dfs:myFields/dfs:dataFields/dfs:CalWasteCodes[" & iState & "]/@Short_name").text
'MsgBox(sName2, MsgBoxStyle.Critical)
'MsgBox(iState, MsgBoxStyle.Critical)
Dim node As String = thisXDocument.DOM.selectSingleNode("/my:myFields/my:CodeConcat[" & iState & "]/my:State").text
MsgBox(node, MsgBoxStyle.Critical)
thisXDocument.DOM.selectSingleNode("/my:myFields/my:CodeConcat[" & iState & "]/my:State").text = Code2 + ", " + sName2
If iState <> numRows2 Then
oParentNode2.appendChild(domXMLNode2.documentElement.cloneNode(True))
Else
End If
Next
'End insert State waste codes******************
End Sub
If anyone has any ideas I would greatly appreciate it. Thanks!