Populate data on the form when it opens - InfoPath Dev
in

InfoPath Dev

Populate data on the form when it opens

Last post 05-09-2005 11:22 PM by Jason. 19 replies.
Page 2 of 2 (20 items) < Previous 1 2
Sort Posts: Previous Next
  • 05-09-2005 08:54 PM In reply to

    • Jason
    • Not Ranked
    • Joined on 04-23-2005
    • Posts 11

    Re: Populate data on the form when it opens

    Hi Agni:

    The above code is inserting only two rows into the table ContactDetails. When it goes to third time the following error I am getting at

    .selectSingleNode("/my:myFields/my:ContactDetails[" & i + 1 & "]/my:CIFNumber").text = strContactId
    -----
    System.NullReferenceException
    Object reference not set to an instance of an object.
    at MySecondInfoPathApp.MySecondInfoPathApp.OnLoad(DocReturnEvent e) in C:\Inetpub\wwwroot\MySecondInfoPathApp\FormCode.vb:line 137
    at Microsoft.Office.Interop.InfoPath.SemiTrust._XDocumentEventSink2_SinkHelper.OnLoad(DocReturnEvent pEvent)

    __________

    The complete code is like this:

    ' Write your code here.
    Dim oDataSet As New DataSet
    Dim lstrQueryXml As String
    lstrQueryXml = "<test><contact>"
    lstrQueryXml &= "<contactid>ContactId1</contactid>"
    lstrQueryXml &= "<firstname>FirstName1</firstname>"
    lstrQueryXml &= "<lastname>LastName1</lastname>"
    lstrQueryXml &= "<ssn>123456789</ssn>"
    lstrQueryXml &= "<crm>CRM1</crm>"
    lstrQueryXml &= "</contact>"
    lstrQueryXml &= "<contact>"
    lstrQueryXml &= "<contactid>ContactId2</contactid>"
    lstrQueryXml &= "<firstname>FirstName2</firstname>"
    lstrQueryXml &= "<lastname>LastName2</lastname>"
    lstrQueryXml &= "<ssn>123456782</ssn>"
    lstrQueryXml &= "<crm>CRM2</crm>"
    lstrQueryXml &= "</contact>"
    lstrQueryXml &= "<contact>"
    lstrQueryXml &= "<contactid>ContactId3</contactid>"
    lstrQueryXml &= "<firstname>FirstName3</firstname>"
    lstrQueryXml &= "<lastname>LastName3</lastname>"
    lstrQueryXml &= "<ssn>123456783</ssn>"
    lstrQueryXml &= "<crm>CRM3</crm>"
    lstrQueryXml &= "</contact>"
    lstrQueryXml &= "<contact>"
    lstrQueryXml &= "<contactid>ContactId4</contactid>"
    lstrQueryXml &= "<firstname>FirstName4</firstname>"
    lstrQueryXml &= "<lastname>LastName4</lastname>"
    lstrQueryXml &= "<ssn>123456784</ssn>"
    lstrQueryXml &= "<crm>CRM4</crm>"
    lstrQueryXml &= "</contact>"
    lstrQueryXml &= "<contact>"
    lstrQueryXml &= "<contactid>ContactId5</contactid>"
    lstrQueryXml &= "<firstname>FirstName5</firstname>"
    lstrQueryXml &= "<lastname>LastName5</lastname>"
    lstrQueryXml &= "<ssn>123456785</ssn>"
    lstrQueryXml &= "<crm>CRM5</crm>"
    lstrQueryXml &= "</contact></test>"

    Dim lXmlDocContacts As New XmlDocument
    lXmlDocContacts.LoadXml(lstrQueryXml)
    Dim root As XmlElement
    root = lXmlDocContacts.DocumentElement
    Dim directoryList As XmlNodeList
    directoryList = root.SelectNodes("/test/contact")

    Dim oParentNode As IXMLDOMNode
    oParentNode = thisXDocument.DOM.selectSingleNode("/my:myFields")
    Dim strFields As String
    strFields = "<my:ContactDetails xmlns:my='http://schemas.microsoft.com/office/infopath/2003/myXSD/2005-04-23T21-52-37'><my:CIFNumber/><my:FirstName/><my:LastName/><my:SSN/><my:CRM/></my:ContactDetails>"
    Dim domXMLNode As IXMLDOMDocument
    domXMLNode = thisXDocument.CreateDOM()

    domXMLNode.async = False
    domXMLNode.loadXML(strFields)

    oParentNode.appendChild(domXMLNode.documentElement)

    Dim i As Integer
    Dim strContactId As String
    Dim strFirstName As String
    Dim strLastName As String
    Dim strSSN As String
    Dim strCRM As String

    For i = 0 To directoryList.Count - 1
    If Not directoryList(i).Item("contactid") Is Nothing Then
    strContactId = directoryList(i).Item("contactid").InnerText
    End If
    If Not directoryList(i).Item("firstname") Is Nothing Then
    strFirstName = directoryList(i).Item("firstname").InnerText
    End If
    If Not directoryList(i).Item("lastname") Is Nothing Then
    strLastName = directoryList(i).Item("lastname").InnerText
    End If
    If Not directoryList(i).Item("ssn") Is Nothing Then
    strSSN = directoryList(i).Item("ssn").InnerText
    End If
    If Not directoryList(i).Item("crm") Is Nothing Then
    strCRM = directoryList(i).Item("crm").InnerText
    End If
    With thisXDocument.DOM
    .selectSingleNode("/my:myFields/my:ContactDetails[" & i + 1 & "]/my:CIFNumber").text = strContactId
    .selectSingleNode("/my:myFields/my:ContactDetails[" & i + 1 & "]/my:FirstName").text = strFirstName
    .selectSingleNode("/my:myFields/my:ContactDetails[" & i + 1 & "]/my:LastName").text = strLastName
    .selectSingleNode("/my:myFields/my:ContactDetails[" & i + 1 & "]/my:SSN").text = strSSN
    .selectSingleNode("/my:myFields/my:ContactDetails[" & i + 1 & "]/my:CRM").text = strCRM
    End With
    Next

    --------------


    Thank you for your time again.

    Jason



  • 05-09-2005 09:26 PM In reply to

    Re: Populate data on the form when it opens

    Come on Jason its so somple you need make out all these, Its plain logic.
    You have inserted just one row with the help of my code, you need to write that in the for loop to insert the total number of nodes required.

    Agni
    InfoPathDev India
  • 05-09-2005 09:41 PM In reply to

    • Jason
    • Not Ranked
    • Joined on 04-23-2005
    • Posts 11

    Re: Populate data on the form when it opens

    Hi Agni:
    Could you please look at the code. For... Next loop is there.
    My problem is after inserting second row when it come to add third row.

    I know you are busy with answering so many questions.

    Thanks
    Jason
  • 05-09-2005 10:22 PM In reply to

    Re: Populate data on the form when it opens

    You should remove "oParentNode.appendChild(domXMLNode.documentElement)" before for loop and have the below line in the for loop
    oParentNode.appendChild(domXMLNode.documentElement.cloneNode(true))

    this will insert the nodes as you loop through the code.

    Hope this helps!

    Agni
    InfoPathDev India
  • 05-09-2005 11:22 PM In reply to

    • Jason
    • Not Ranked
    • Joined on 04-23-2005
    • Posts 11

    Re: Populate data on the form when it opens

    Hi Agni:

    It worked just fine... Awesome.
    Thanks a lot again.

    Jason
Page 2 of 2 (20 items) < Previous 1 2
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.