VB and repeating group. - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

VB and repeating group.

Last post 07-30-2007 06:56 AM by Catharine. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 07-25-2007 11:00 AM

    VB and repeating group.

    Hi

    First - I am new to VB so I know that I am missing something really trivial, but I have been looking at this for days and my head hurts from the brickwalls I am hitting.  So please take it easy on me !!

    I have a form with one ordinary field, and one repeating group with 4 fields in the group. - here is the xml from my testing  (Sorry for the Harry Potter names )

    <my:Name1>Hello</my:Name1>
    <my:TestGroup1>
        <my:TG1Field1>Harry</my:TG1Field1>
        <my:TG1Field2>Ron</my:TG1Field2>
        <my:TG1Field3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">5</my:TG1Field3>
        <my:TG1Field4>false</my:TG1Field4>
    </my:TestGroup1>
    <my:TestGroup1>
         <my:TG1Field1>Fred</my:TG1Field1>
         <my:TG1Field2>George</my:TG1Field2>
         <my:TG1Field3>12</my:TG1Field3>
         <my:TG1Field4>false</my:TG1Field4>
    </my:TestGroup1><my:TestGroup1>
        <my:TG1Field1>Albus</my:TG1Field1>
        <my:TG1Field2></my:TG1Field2>
        <my:TG1Field3 xmlns:xsi="http://www.w3.org/2001/XMLSchema instance"xsi:nil="true"></my:TG1Field3>
        <my:TG1Field4>false</my:TG1Field4>
    </my:TestGroup1></my:myFields>

    I have put a validation check on the repeating group. I don't know how many repeating lines there will be.

    When there is a change to the repeating group I want to go to the first record, get the value of eg field1, compare it to other values in the other field1s and field2s and perform an action..... 

    I have tried ....below.... and I only get the record that triggered the validation returned. - and the g1.current.value is all 4 fields run together. 

    Dim myform As XPathNavigator = e.Site.CreateNavigator
    Dim mygroupnam As String = e.Site.Name
    Dim g1 As XPathNodeIterator = myform.Select(mygroupnam & "/*", NamespaceManager)
    Do While g1.MoveNext
    MessageBox.Show(g1.Current.Value)
    Loop

    I have also tried  Select(mygroupnam & "/TG1Field1", NamespaceManager) and the g1.current.value is all 4 fields run together - and the count is 0

    I have tried various iterations (movetoParent, movetoChild, movetoFirstChild, SelectChildren, .....)and I cannot seem to get the four fields separated, and the repeating groups out at the same time.

    I know I am doing something fundamentally wrong - I have tried reading the help and "working with XML Data using the Xpathnavigator clss in Infopath 2007 form templates" but nothing is triggering a Eureka moment.   I would be grateful for your help.

    Catharine

  • 07-27-2007 06:32 AM In reply to

    Re: VB and repeating group.

    Hi Catharine,

    If you are just trying to do data validation, why use code at all?  Here is a tutorial on narrowing down drop-down list choices depending on the choices made in other rows:

    http://www.infopathdev.com/blogs/matt/archive/2006/05/23/Filter-a-Repeating-Drop_2D00_Down-List-on-Previous-and-Future-Selections.aspx

    If this is not what you're trying to do, can tell us what you're trying to accomplish - there might be a better way altogether.

    Matt Faus / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 07-27-2007 08:01 AM In reply to

    Re: VB and repeating group.

    Hi, Thank you for your reply.

    I have looked at the example.  None of my fields are dropdown lists but I have book marked it for the future...

    Where to start...... I was trying to understand the process/method for comparing values in a repeating table for several uses.

    On part of my form I need to collect person information (number indeterminate - and not dependent on other fields in form).  eg

    First NameSecond NameInfo1Info2 Primary Info 3Generated Number
    FredBlogsabno110
    Georgeblogscdno611
    JamesDoeefyes912
    FredDerfghno113

    I have set up a repeating table for the information. 
    I need to ensure that only one of the records in that repeating table has primary set to yes.
    I need to ensure that the combination of first name/second name is unique (even if they are in different cases)
    I need to generate a unique number to each record in the repeating table
    I need to create a calculation  and total based on info3
    I need to compare the combination of first name/second name with values in a secondary data source - again regardless of case - have only managed to do the compare against the first record in the secondary data source

    As yet I have failed to do these things without resorting to code.....

    My though process was....
    1.Trigger Event on change in the Repeating Table
    2. If the change was in the primary field - loop through all the records and count where the primary was yes - then give an error if necessary
    3. If the change was in the column requiring calculation/total then loop through, perform total and set field value outside of repeating table
    4. If the change was in the name fields again loop through and compare with other values

    Have I been going in completely the wrong direction? 

    Catharine

  • 07-27-2007 09:35 AM In reply to

    Re: VB and repeating group.

    Hi Catharine,

    I think you are underestimating the power of XPath! :) 

    Let's assume your schema is this:

    my:myFields
    --my:group1
    ----my:group2
    ------my:FirstName
    ------my:SecondName
    ------my:Info1
    ------my:Info2
    ------my:Primary
    ------my:Info3
    ------my:ID

    Only one primary = yes
    I would put a data validation rule on t he my:Primary node.  Double-click the node in the designer, go to "Rules and Data Validation" tab, and click to add a custom Data Validation.  Use the condition "../preceding-sibling::my:group2[my:Primary = 'yes']", and then setup a custom message.  Now, when they insert a new row and try to check Primary even tho one above is checked it will be outlined in red as a data validation error.

    Ensure firstName/LastName combo is unique
    This one is a little more tough. You might have to use code here, but try this first.  Same as above, just use this condition on the my:FirstName and my:SecondName nodes (repeat on both nodes): "../preceding-sibling::my:group2[ translate( "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "abcdefghijklmnopqrstuvwxyz", concat(my:FirstName, my:SecondName)) = concat(current()/my:FirstName, current()/my:SecondName) ]".  You might have to play around with the placement of the current(). Use translate on the second part of the condition, too.

    Generate a unique number for ever record in the repeating table
    Why do you need to do this? You can do it by setting the default value to "count(../preceding-sibling::my:group2) + 1".  We have a blog post on this in InfoPathdev.com

    Create a calculation and total based on Info3
    Easy.  Set the default value of your total node to sum( /my:myFields/my:group1/my:group2/my:Info3 ).

    FirstName/SecondName comparison to secondary DOM
    Same as above, just point it to the secondary DOM.

     Well, that's a lot to churn through, but you did ask quite a few questions!  Each one of them could be it's own thread, haha.  You seem like a pretty adept programmer, but I think you are thinking about InfoPath wrong.  It's a very data-centric programming model.  You should have a similar mindset with Infopath as you do when you are writing SQL applications.  Plus, XPath is kind of similar to SQL... kinda.

     Anyway, hope this helps!  Try searching around on the forums for answers to each of your individual questions, I know we have gone over some of them before.

    Matt Faus / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 07-30-2007 06:56 AM In reply to

    Re: VB and repeating group.

     Hi

    Thank you soooo much.  I wasn't even considering the use of XPATH - I hope this will be my Eureka moment with INFOPATH.  I have been trying to use the solution you posted for the Primary field and cannot get it to work - yet - I have tried a number of iterations.  At the moment the Primary field is highlighted in red all the time. And the screen tip and message do not come up at all.

    I have the data source set exactly as your example.  The primary field is a check box with yes and no values. 

    In the data validation screen the condition is  the expression   "../preceding-sibling::my:group2[my:Primary = 'yes']"  (I can't seem to show u a screen copy)

    Have I missed something out ?

    Catharine

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