Pre-selecting the year for an InfoPath Date Picker control

by S.Y.M. Wong-A-Ton

Learn how you can save time and increase efficiency by pre-selecting and setting the year at which an InfoPath date picker control should start displaying dates in its calendar.

Introduction

If you’ve ever used the Date Picker control in InfoPath, you might know that one of its limitations is the ability to quickly select a particular year or month.

For example, it works fine for dates in the current year, but what if you want to select a date 10 or 20 years ago?

Currently, you have two options if you want to select a date such as for example March 1, 1995:

  1. Type the value directly into the date picker control.
  2. Click on the back arrow on the calendar of the date picker control to navigate through each and every month starting from 2009 until you reach March 1995.

Setting the year for the calendar of an InfoPath date picker control

If you want to avoid the two scenarios mentioned above, you can do the following:

  1. Add a Drop-Down List Box and Date Picker control to your InfoPath form template.
  2. Fill the Drop-Down List Box control with the dates you want by using either static values or retrieving the values from a secondary data source.

    For example, you could use static date values for years by double-clicking the drop-down list box to open its Properties dialog box and entering the values in the List box entries section on the Data tab.

    Depending on whether your date picker control is set to accept dates or dates and times, you must use the appropriate date format when entering the dates for the years. Here, my date picker control accepts only dates, so I used 1995 as the Display name and 1995-01-01 as the Value when adding an entry for the year 1995 to my drop-down list box.

  3. The last step is to add a Rule to the drop-down list box. The rule must set the value of the date picker control to the value of the drop-down list box as follows:

    Set a field's value: selectedDateDatePicker = .

    where selectedDateDatePicker is the name of the date picker control.

    Note: You can add a rule by clicking on the Rules button on the Properties dialog box of the drop-down list box.

Pre-selecting the year for an InfoPath date picker control
Figure 1. Pre-selecting the year for an InfoPath date picker control.

Now instead of having to click through every month in every year of the date picker to go from the date of today and arrive at a date in the past (or future), all you have to do is select the year from the drop-down list box, and the rule will kick in to set the date picker and its calendar to start at January 1 of the year you selected (depending on the values of the dates you used in your drop-down list box).

This technique allows you to click through less than 12 months to arrive at the date you require. You could extend this technique to also include pre-selection of months.

 Subscribe (RSS | Email)

Related Posts

  1. 2 Responses to “Pre-selecting the year for an InfoPath Date Picker control”

  2. My comment is unrelated, but I have a question. I am populating data on my form from a SharePoint list and auto-populating another field based on the list item that is selected. My logic is: RequestorPhone = @BusinessPhone[@ID = RequestorName].

    This works fine and dandy, but when I publish my form to SharePoint site, the value that is displayed on the site is ID of the Requetor and I need it to display the Requestor Name.

    By Phil on May 1, 2009

  3. Hi Phil,

    Thanks for your question. Can you provide more info as to where you’re trying to display the Requestor Name, and how you’ve set up your InfoPath form template?

    If the RequestorPhone is working, you should be able to do the same for the RequestorName.

    And have you already seen this article: How to simulate Excel’s VLOOKUP function in InfoPath to look up data in a secondary data source using rules and filters?

    By S.Y.M. Wong-A-Ton on May 1, 2009

Comments to this post were closed 30 days after it was published.

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 of S.Y.M. Wong-A-Ton. Usage of 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, S.Y.M. Wong-A-Ton.

Working with InfoPath