InfoPath Basics: Make a control required based on a condition
Learn how you can use data validation in InfoPath to make a field required based on a condition or the value of another field.
Making a control required in InfoPath means applying data validation to that control.
There are 3 ways to apply InfoPath data validation:
- Use data types
- Use data validation rules
- Use rules
If you want to make a control required based on a condition, you’d have to use method 2 or 3 listed above.
Suppose you have a text box and a check box on an InfoPath form (see Figure 1) and you want to force a user to enter something in the text box, i.e. make the text box required, whenever the check box is selected.
Figure 1. InfoPath form with a text box and check box.
A quick way to do this is by adding an InfoPath validation rule on the text box with a condition that the check box must be selected to run the rule and thus make the text box a required field.
If field1 is the text box and field2 is the check box on your InfoPath form, you can add a data validation rule as follows:
- Double-click the Text Box control to open its Properties dialog box.
- On the Text Box Properties dialog box, click Data Validation.
- On the Data Validation (field1) dialog box, click Add.
- On the second Data Validation (field1) dialog box, add the following two conditions:
field2 is equal to TRUE
field1 is blank
- On the second Data Validation (field1) dialog box, type a message in the ScreenTip and Message text boxes to tell the user that this field must be filled in, and click OK.
- Click OK to close all dialog boxes.
Now whenever you select the check box, a red asterisk will appear in the text box as an indication that it is required and thus must be filled in.
Figure 2. A required field on an InfoPath form based on a condition.
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.