Adding rows to repeating tables and its nested repeating tables all at once. - InfoPath Dev
in

InfoPath Dev

Adding rows to repeating tables and its nested repeating tables all at once.

Last post 03-23-2011 02:38 PM by S R SP. 0 replies.
Page 1 of 1 (1 items)
Sort Posts: Previous Next
  • 03-23-2011 02:38 PM

    • S R SP
    • Not Ranked
    • Joined on 03-23-2011
    • Posts 1

    Adding rows to repeating tables and its nested repeating tables all at once.

    Hello

     I am trying to create an expense report based on infopath. I created a repeating tables to capture dates/cities/accounts and departments and a nested table for details such as airlines/lodging/food/taxi etc.

     I created a button where the code looks at start date and end date and creates entries for each of the dates and this works...when I tried to add code to add rows to the nested table i am getting an error

    NullReferenceException was unhandled by user code. Object reference not set to an instance of an object.

    Here's the code I have so far. (See Below).

    Appreciate the assistance.

    Regards

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

     

    Public Sub CTRL104_5_Clicked(ByVal sender As Object, ByVal e As ClickedEventArgs)

    ' Write your code here.

    Dim root As XPathNavigator = Me.CreateNavigator

    Dim myNamespace As String = NamespaceManager.LookupNamespace("my")

    Dim nav As XPathNavigator = CreateNavigator()

    Dim count As Integer = 0

    Dim diff As Integer = nav.SelectSingleNode("/my:myFields/my:difference", NamespaceManager).Value

    Dim startDate1 As Date = nav.SelectSingleNode("/my:myFields/my:startDate", NamespaceManager).Value

    Dim startdate2 As Date

    ' Retrieve the first row of the repeating table

    Dim XPath1 As String

    Dim date3 As String

    Dim domNav As XPathNavigator = MainDataSource.CreateNavigator()

    Dim itemNav As XPathNavigator = domNav.SelectSingleNode( _

    "/my:myFields/my:group5/my:group6[1]", _

    NamespaceManager)

    ' Delete the row

    If itemNav IsNot Nothing Then

    itemNav.DeleteSelf()

    End If

     

    For count = 1 To diff

    Using writer As XmlWriter = MainDataSource.CreateNavigator().SelectSingleNode( _

    "/my:myFields/my:group5", NamespaceManager).AppendChild()

    writer.WriteStartElement("group6", myNamespace)

    'date3 = DatePart(dateinterval.month, startDate1.AddDays(count - 1)) & "-" & datepart(dateinterval.day, startDate1.AddDays(count - 1))

    startdate2 = startDate1.AddDays(count - 1)

    date3 = startDate2.Year &
    "-" & Format(startDate2.Month, "##") & "-" & startDate2.Day

    ' writer.WriteElementString("field9", myNamespace, startDate1.AddDays(count - 1).ToString("mm-dd-yyyy"))

    writer.WriteElementString("field9", myNamespace, date3.ToString)

    writer.WriteElementString("field6", myNamespace, "Cell 2")

    writer.WriteElementString("field8", myNamespace, "Cell 3")writer.WriteElementString("field7", myNamespace, "Cell 4")

    writer.WriteEndElement()

    writer.Close()

     

    Using writer1 As XmlWriter = domNav.SelectSingleNode( _

    "/my:myFields/my:group5/my:group6/my:group7", NamespaceManager).AppendChild()

    writer1.WriteStartElement("group8", myNamespace)

    writer1.WriteElementString("field11", myNamespace, "Airline (Paid by Employee)")

    writer1.WriteElementString("field49", myNamespace, "0")

    writer1.WriteEndElement()

    writer1.Close()

    End Using

     

    End Using

     

    Next

    End Sub

    End Class

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