Auto-populate a drop-down list box with past and future dates

This InfoPath demo is the completed solution for recipe 106 of InfoPath 2013 Cookbook in which a drop-down list box is populated with dates that fall 7 days in the past and 7 days in the future starting from the currently selected date.

In recipe 106 you will learn how to populate a drop-down list box with dates that fall 7 days in the past and 7 days in the future starting from the currently selected date.

Get more solutions from InfoPath 2013 Cookbook which is available on Amazon.com
OR
Watch the next InfoPath demo: Populate a drop-down list box with dates excluding weekends

InfoPath demo video transcript:

Here I'm in SharePoint 2013 where I've already published an InfoPath form template to this SharePoint form library. So if I click new document to add a new form, you'll see that as soon as the InfoPath form opens, it will display this drop-down list box control on it, containing the current system date.

And if I open the drop-down list box, you'll see that it contains a total of 15 dates with 1 2 3 4 5 6 7 of those dates falling in the past starting from the currently selected date, and 1 2 3 4 5 6 7 of those dates falling in the future starting from the currently selected date.

I can select a different date and then when I open the drop-down list box, again you'll see the 15 dates, but then this time, they are starting from the currently selected date, which is the 28th of June here... falling in the past again and falling in the future. You can continue selecting dates and moving up in time like this.

If you have a form, which you've previously saved with an older date. For instance, I've got this form here in which I saved the 25th of February. You'll see that when I open the drop-down list box, again we have these 15 dates with 7 falling in the past starting from the currently selected date and 7 falling in the future starting from the currently selected date. And then again you can select a different date and continue moving up in time like this, or moving back in time.

This solution is flexible in that you can combine it with other solutions. In this case, I've combined it with the techniques from recipe 65 in which I've managed to store this month name with 3 characters. As you can see, we can move up and move back in time like this.

And in this solution, I've combined recipe 106 with recipes 65 to display the month and 67 to display this character in front of the date that represents the day of the week with an F being Friday and this S being Saturday. And again you can move up in time like this or move back in time like this.

 

Related InfoPath Demo Videos:

 

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