Programmatically (VB) add rows to a repeating section and set values (Questionnaire DB) - InfoPath Dev
in

InfoPath Dev

Programmatically (VB) add rows to a repeating section and set values (Questionnaire DB)

Last post 04-19-2012 09:41 AM by JConIP. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 04-18-2012 02:24 PM

    • JConIP
    • Not Ranked
    • Joined on 04-18-2012
    • Posts 2

    Programmatically (VB) add rows to a repeating section and set values (Questionnaire DB)

    Challenge: I’ve read and search through this site and found various methods described in part and I have not been able to implement any successfully.  E.g.:

    ·         newRow As XPathNavigator = sectionNode.Clone()

    ·         writer As XmlWriter = sectionNode.AppendChild()

    ·         Me.CurrentView.ExecuteAction("xCollection::insert", "RepeatTest_1")

     

    Task:

    ·         Programmatically (VB) add rows to a repeating section and

    ·         Define two values:

    o   A Foreign Key that allows limitation of a view to a specific set of question responses / questionnaire form instance.  This requires filtering or another method on the form.

    o   A question Foreign  Key that allows definition of which text and controls to display for that element / detail row

    Goal: Use a generic Questionnaire row design with its set of controls which should hide, show, etc. based on the type of form instance they are representing along with its individual questions. 

    ·         The bank of ‘forms’/question sets, questions, types, and answers are normalized into secondary record sources.

    ·         Before populating the row, there are no rows visible to copy.

    Environment: InfoPath Forms Designer 2007 (using VB) against an Access DB on a file server.  Users are field staff. (No SharePoint)

    What best method and insight might someone share if to get me on track? Sample code anyone? I've been working with InfoPath just 3 months and could use a little direction here.  Thanks in advance.

  • 04-19-2012 09:41 AM In reply to

    • JConIP
    • Not Ranked
    • Joined on 04-18-2012
    • Posts 2

    Re: Programmatically (VB) add rows to a repeating section and set values (Questionnaire DB)

    I've made some progress.  I located the following example (http://www.bizsupportonline.net/infopath2007/programmatically-add-row-repeating-table-xmlwriter.htm):

    Dim myNamespace As String = NamespaceManager.LookupNamespace("my")
    Using writer As XmlWriter = MainDataSource.CreateNavigator().SelectSingleNode( _
    "/my:myFields/my:group1", NamespaceManager).AppendChild()
    writer.WriteStartElement("group2", myNamespace)
    writer.WriteElementString("field1", myNamespace, "Cell 1")
    writer.WriteElementString("field2", myNamespace, "Cell 2")
    writer.WriteElementString("field3", myNamespace, "Cell 3")
    writer.WriteEndElement()
    writer.Close()
    End Using

    This test modification works fine. 

    Dim myNamespace As String = NamespaceManager.LookupNamespace("my")Using writer As XmlWriter = MainDataSource.CreateNavigator().SelectSingleNode( _"/dfs:myFields/my:RepeatContainer", NamespaceManager).AppendChild()writer.WriteStartElement("RepeatTable", myNamespace)writer.WriteElementString("PK", myNamespace, "1")writer.WriteElementString("Desc", myNamespace, "Item Desc")writer.WriteEndElement()writer.Close()

    End Using

    This adaptation gives an error of "Schema validation found non-data type errors." 

    Dim strXPath As String = _"/dfs:myFields/dfs:dataFields/d:tblPractice/d:tblSite/d:tblReview/d:tblReviewForm"Dim strPKReviewForm As String = RetrieveXPathValueAsString( _"/dfs:myFields/dfs:dataFields/d:tblPractice/d:tblSite/d:tblReview/d:tblReviewForm/@PKReviewForm")Dim myNamespace As String = NamespaceManager.LookupNamespace("d")Using writer As XmlWriter = MainDataSource.CreateNavigator().SelectSingleNode( _strXPath, NamespaceManager).AppendChild()writer.WriteStartElement("tblData", myNamespace)writer.WriteElementString("PKData", myNamespace, "")writer.WriteElementString("FKReviewForm", myNamespace, strPKReviewForm)writer.WriteElementString("FKFormQ", myNamespace, "1")writer.WriteElementString("DPValDec", myNamespace, "")writer.WriteElementString("DPValDate", myNamespace, "")writer.WriteElementString("DPValTxt", myNamespace, "")writer.WriteEndElement()writer.Close()

    End Using

     

    • Do I have the correct Namespace prefix for a Primary/Main datasource? 
    • Do I include Elements for Primary and Parent entity Foreign keys?
    • Do I populate the Foreign key? 
    • Other suggestions?

    Again, Thanks,

     

    JC

     

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