InfoPath Basics: Make a control required based on a condition

Filed under: InfoPath 2007

Learn how you can use data validation in InfoPath to make a field required based on a condition or the value of another field.

ADVERTISEMENTS

Making a control required in InfoPath means applying data validation to that control.

There are 3 ways to apply InfoPath data validation:

  1. Use data types
  2. Use data validation rules
  3. 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.

Example:
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.

InfoPath form with a text box and check box
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:

  1. Double-click the Text Box control to open its Properties dialog box.
  2. On the Text Box Properties dialog box, click Data Validation.
  3. On the Data Validation (field1) dialog box, click Add.
  4. On the second Data Validation (field1) dialog box, add the following two conditions:

    field2 is equal to TRUE

    And

    field1 is blank

  5. 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.
  6. 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.

A required field on an InfoPath form based on a condition
Figure 2. A required field on an InfoPath form based on a condition.

 


Related Posts

 

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.

InfoPath 2013 Cookbook: 121 Codeless Recipes for Beginners

InfoPath 2013 Cookbook 2: 121 Codeless Recipes for SharePoint 2013

InfoPath 2010 Cookbook: 101 Codeless Recipes for Beginners

InfoPath 2010 Cookbook 2: 101 Codeless Recipes for SharePoint 2010

InfoPath 2010 Cookbook 3: 101 Code Recipes for C# Developers

InfoPath 2010 Cookbook 4: 101 Code Recipes for VB Developers

InfoPath 2010 Cookbook 5: Integrating InfoPath with Excel and Excel Services