Auto-populate a repeating table in InfoPath with sequential dates

Applies to: InfoPath 2007

Learn how you can use a function and formulas in InfoPath 2007 to populate rows in a repeating table with sequential dates by entering one date and having the rest of dates automatically calculated and displayed.

ADVERTISEMENTS

Problem

You have an InfoPath repeating table that contains a column with an InfoPath date picker control. You want to be able to enter a date in any row of the repeating table and have all of the dates in subsequent rows automatically calculated, sequentially incremented, and displayed.

Solution

Use the addDays function and formulas to calculate and display sequential dates in rows of a repeating table in InfoPath.

Discussion

You can achieve this functionality as follows:

  1. In InfoPath 2007, create a new Blank form template.
  2. Add a Repeating Table control with a hidden column to the InfoPath form template.
  3. Convert the text box in the first column of the repeating table into a Date Picker control. Make its Date type Date (date). Your InfoPath form template and Main data source should now resemble the following figure:
    InfoPath form template with repeating table and date picker controls in Design mode
    Figure 1. InfoPath form template with repeating table and date picker controls in Design mode.

  4. On the Data Source task pane, double-click the field you made hidden in the repeating table to open its Properties dialog box. Here we'll assume that you made field2 in the repeating table hidden.
  5. On the Field or Group Properties dialog box, click the formula button behind the Value text box under the Default Value section.
  6. On the Insert Formula dialog box, select the Edit XPath (advanced) check box.
  7. On the Insert Formula dialog box, copy and paste the following formula into the Formula text box:

    ../preceding-sibling::my:group2[1]/my:field1

    and click OK.

    Here field1 represents a date picker control in the first column of the repeating table and the field for which you want to sequentially calculate and display dates.

  8. On the Field or Group Properties dialog box, ensure that the Update this value when the result of the formula is recalculated check box is selected, and then click OK.
  9. Double-click the Date Picker control in the first column of the repeating table to open its Properties dialog box.
  10. On the Date Picker Properties dialog box, click the formula button behind the Value text box under the Default Value section.
  11. On the Insert Formula dialog box, select the Edit XPath (advanced) check box.
  12. On the Insert Formula dialog box, copy and paste the following formula into the Formula text box:

    xdDate:AddDays(../my:field2, 1)

    and click OK.

    Note: You could also click the Insert Function button, select the addDays function, and then select field2 from the repeating node for the repeating table as the date field to use, and enter 1 as the amount of days to add to the date.

  13. On the Date Picker Properties dialog box, ensure that the Update this value when the result of the formula is recalculated check box is selected, and then click OK.

You should now have a fully functional form so that after you add a couple of empty rows to the repeating table, you can enter a date in one of the date picker controls, and have all of the date picker controls in the subsequent rows automatically populated with sequential dates.

InfoPath form before populating the repeating table with sequential dates
Figure 2. InfoPath form before populating the repeating table with sequential dates.

InfoPath form after entering a date in the second row and automatically populating the repeating table with sequential dates in all of the subsequent rows
Figure 3. InfoPath form after entering a date in the second row and automatically populating the repeating table with sequential dates in all of the subsequent rows.

 


Related InfoPath Articles:

 

Copyright: This article may not be used on web sites (whether personal or otherwise), copied, disseminated, altered, printed, published, broadcasted, or reproduced in any way without an expressed written consent. The techniques demonstrated in this article may be used within any Microsoft InfoPath project. This article is provided without any warranties. Copyright for this article is non-transferrable and remains with the author.

InfoPath 2013 Cookbook: 121 Codeless Recipes for Beginners

InfoPath 2013 Cookbook 2: 121 Codeless Recipes for SharePoint 2013

InfoPath 2010 Cookbook: 101 Codeless Recipes for Beginners

InfoPath 2010 Cookbook 2: 101 Codeless Recipes for SharePoint 2010

InfoPath 2010 Cookbook 3: 101 Code Recipes for C# Developers

InfoPath 2010 Cookbook 4: 101 Code Recipes for VB Developers

InfoPath 2010 Cookbook 5: Integrating InfoPath with Excel and Excel Services