With Microsoft InfoPath 2010, you can specify control formatting rules that are based on conditions that occur in the form. If the specified conditions are true when a user fills out a form with formatting rules, then the formatting is applied. Formatting rules can be used to apply bold, underline, italic, strikethrough, font color, and background color to controls; or hide/show or disable controls.
In this article
Formatting rule examples
The following are some examples of how to use formatting rules in a form template:
- Hide the shipping address section unless the Specify Shipping Address check box is selected.
- Change the font color to blue and the font style to bold for all expenses that require a receipt.
- Change control background color in a repeating table based on the value of a text box in the row. For example, make all controls red in a row for an overdue item and green for items that are on schedule.
- Mark financial entries with red text when they are less than $0 and green text when they are $0 or more.
- Filter rows in a repeating table.
Note You can also use a validation rule to display a message when a user enters incorrect values into a form.
Top of Page
Use the Add Rule button
Out-of-the-box formatting rules can be added by using the Add Rule command.
- Click a control.
- On the Home tab, in the Rules group, click Add Rule.
- Click the type of condition that the rule needs to meet in order to apply, such as Is Blank if you want the rule to apply if the value of the field is blank.
- Click the type of formatting to apply, such as shading the background color of the cell or modifying the font to indicate a warning.
Note Depending on the type of condition that you chose, you might be asked to enter additional information.
When finished, the Rules task pane appears and you can make any necessary changes to the rule.
Use the Rules task pane
Complete the following steps to add a formatting rule from the Rules task pane:
- Create a formatting rule
- Click a control.
- If the Rules task pane is not visible, then, on the Home tab, in the Rules group, click Manage Rules.
- Click New.
- Click Formatting.
- Enter a name for the rule in the Details for text box.
- Specify the conditions.
- In the condition section, click None.
- If the condition for your rule is based on a field, complete the following:
- In the first box, click a field or select Select a field or group.
- In the second box, click an operator such as is equal to.
- In the third box, enter a value.
Note It is also possible to base a rule on an expression or a set of signable data. For more information about these advanced scenarios, see the corresponding section under Advanced condition scenarios.
- Click And to add another condition, and then repeat step 2 or click OK.
Note After adding a second condition, the And button is replaced with a box. Leave and selected if both the first and each subsequent condition needs to be true for the conditional formatting to be applied. Otherwise, if only one of the conditions should be true for the conditional formatting to be applied, click or.
- Specify the formatting.
- Make the desired selections from the Formatting section. From this section you can indicate that text in the control is bold or underlined, change the color of the text or background color of the control, or turn on or off the control.
Note If you add multiple formatting rules and more than one is true, only the formatting for the first true condition is applied.
Data entry patterns
Formatting rules can be based on the text pattern that a user enters into a text field. For example, if you want to collect a United States ZIP code, then you want to make sure that only five numbers, no less, no more, and no alphabetical characters are entered. Likewise, if you want a user to enter an email address , then you can match the input to a pattern that includes text, an “@” symbol, a domain, and a domain suffix such as “.com”.
To do this, from the Operator text box, select Matches Pattern when building the condition, and then select the Select a pattern option. The Data Entry Pattern dialog appears, from which you can select from several pre-defined, standard patterns. If one of these patterns does not meet your needs, then you can indicate a custom pattern. Custom patterns can require the use of special characters, which can be easily inserted by selecting them from the Insert special character box.
Advanced condition scenarios
The following are advanced scenarios that you can use when setting the condition of a data formatting rule.
- Base a rule on an expression
An expression is a set of values, fields or groups, functions, and operators. You can use an expression to set the value of a field in such scenarios as automatically including today’s date on a form, or adding the cost of items entered into an expense report to get the total.
- In the first box, click an expression.
- In the second box, enter the expression.
- Base a rule on a set of signable data
If a form requires a digital signature and it has not been signed, you might want to disable the submit button. Or, for example, you can set the background color of the Signature field be a red until a the form is signed. This condition is only supported in InfoPath Filler forms.
- In the first box, click Select set of signable data.
- In the Select Set of Signable Data dialog box, select the set of signable data, and then click OK.
- In the second box, click a condition, and then, in the third box, select any necessary criteria.
Note For more information, see Digital Signatures in InfoPath 2010.
- Base a rule on a user’s role
While it is possible to create a form with different views, and display the appropriate view to a user, based on their role, it is also possible to have one view for all users, and hide or display individual controls in the view to a user based on their role. You can also use this to automatically fill in a user’s manager, department, or other information, based on their role. User roles are only supported in InfoPath Filler forms.
- In the first box, click User’s current role.
- In the second box, click the operator, such as is equal to.
- In the third box, click the role or Manage roles to manage user roles.
Top of Page