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.
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.
-
If the Data Source task pane is not visible, click Data Source on the View menu.
-
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.
-
Click the Data tab.
-
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.
-
-
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.
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.
-
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.
-
Click the Data tab.
-
Under Validation and Rules, click Rules.
-
In the Rules dialog box, click Add.
-
In the Name box, type a name for the rule.
-
To specify when the rule should run, click Set Condition.
-
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.
-
In the Rule dialog box, click Add Action.
-
In the Action list, click Set a field's value.
-
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.
-
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.
-
-
To test your changes, click Preview on the Standard toolbar, or press CTRL+SHIFT+B.
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.
-
On the Tools menu, click Form Options.
-
Click Advanced in the Category list, and then click Edit Default Values.
-
In the Edit Default Values dialog box, select the field whose default value you want to set.
-
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.
-
-
Repeat step 3 and step 4 for each field whose default value you want to set.
-
To test your changes, click Preview on the Standard toolbar, or press CTRL+SHIFT+B.
No comments:
Post a Comment