Applies ToInfoPath 2010 InfoPath 2013

When designing a Microsoft Office InfoPath 2007 form template, you can assign default values to controls that are bound to fields in the form template. A default value is the value that appears automatically in a control when the user opens a form to fill it out.

In this article

Overview of default values

When you design a form template, you can assign default values to controls in order to help users fill out your form faster. For example, if you create an employee expense report form template, you can assign today's date as the default value for a date picker control. As a result, the current date is automatically populated in the date picker control when the user opens the form, and they do not have to manually enter the date.

You can set default values in your form template by:

  • Assigning a specific value to a control, which is automatically populated when the user opens the form to fill it out.

  • Using a rule to set a default value for a control, based on data that the user enters into another control on the form.

  • Setting all of the default values for your form template at once.

Top of Page

Set the default value for a control

When you set a default value for a field in your form template, you are specifying the value that should appear automatically in the control when a user fills out a form based on that form template.

  1. If the Data Source task pane is not visible, click Data Source on the View menu.

  2. In the Data Source task pane, right-click the field whose default value you want to set, and then click Properties on the shortcut menu.

  3. Click the Data tab.

  4. Do one of the following:

    • To use a specific value as the default value, type the default value in the Value box.

    • To use an XPath expression to create the default value, click Insert Formula , and then in the Insert Formula dialog box, create the XPath expression.

      Tip: To automatically update the value in the selected field each time the formula is calculated, select the Update this value when the result of the formula is recalculated check box in the Field or Group Properties dialog box.

  5. To test your changes, click Preview on the Standard toolbar, or press CTRL+SHIFT+B.

Technical details

When you set the default value for a control, you are also setting the default value for the field to which that control is bound. Any control that is bound to that field will be assigned the same default value.

If the default value is a specified value, that value is stored in the template.xml file associated with the form template. To programmatically change the default value, change the value of the appropriate field in the template.xml file. If the default value is the result of an XPath expression, the expression is stored in the manifest.xsf file, in the xsf:calculatedField element for the field.

Top of Page

Set the default value using a rule

You can use a rule to set the default value of a control based on the value of another control. A rule is an action that occurs when a condition in the form is met. For example, you might design a form template with a control for the state and another control for the ZIP Code. When a user enters a ZIP Code in the ZIP Code control, the State control is automatically populated with the correct state.

In order to complete this procedure, you must have two controls in your form template — one that the user will enter data into, and one that will be populated with a default value, based on the data entered into the first control.

  1. Double-click the control that the control with the default value will be based on.

    For example, in the case of the State and ZIP Code controls, you would double-click the ZIP Code control.

  2. Click the Data tab.

  3. Under Validation and Rules, click Rules.

  4. In the Rules dialog box, click Add.

  5. In the Name box, type a name for the rule.

  6. To specify when the rule should run, click Set Condition.

  7. In the Condition dialog box, enter the condition, and then click OK.

    For example, if you want a default value to be added to a control when the user enters data into another control, in the first box, click the field that the user will enter data into, click is equal to in the second box, and in the last box, enter the data the user will enter into the control.

  8. In the Rule dialog box, click Add Action.

  9. In the Action list, click Set a field's value.

  10. Click next to the Field box, and then in the Select a Field or Group dialog box, click the control whose default value you want to set.

  11. Do one of the following:

    • To use a specified value as the default value, type the value in the Value box, and then click OK.

    • To use an XPath expression to create the default value, click Insert Formula , enter the formula in the Insert Formula dialog box, and then click OK.

  12. To test your changes, click Preview on the Standard toolbar, or press CTRL+SHIFT+B.

Top of Page

Set all of the default values for a form

If you know all of the controls in your form template that will have a default value, and that the default values are not based on rules, you can set all of the default values at once.

  1. On the Tools menu, click Form Options.

  2. Click Advanced in the Category list, and then click Edit Default Values.

  3. In the Edit Default Values dialog box, select the field whose default value you want to set.

  4. Do one of the following:

    • To use a specified value as the default value, type the default value for the field in the Default value box, and then click OK.

    • To use an XPath expression to create the default value, click Insert Formula , and then in the Insert Formula dialog box, create the XPath expression.

      Tip: To automatically update the value in the selected field each time the formula is calculated, select the Update this value when the result of the formula is recalculated check box in the Edit Default Values dialog box.

  5. Repeat step 3 and step 4 for each field whose default value you want to set.

  6. To test your changes, click Preview on the Standard toolbar, or press CTRL+SHIFT+B.

Top of Page

Need more help?

Want more options?

Explore subscription benefits, browse training courses, learn how to secure your device, and more.

Communities help you ask and answer questions, give feedback, and hear from experts with rich knowledge.