Microsoft KB Archive/827004

= How to create a required string field for an InfoPath data source =

Article ID: 827004

Article Last Modified on 4/12/2007

-

APPLIES TO


 * Microsoft Office InfoPath 2007
 * Microsoft Office InfoPath 2003
 * Microsoft Office InfoPath 2003, Service Pack 1 (SP1)

-



IN THIS TASK

 * SUMMARY
 * Introduction
 * Designate a Required String Field in a Data Source That Is Built with InfoPath
 * Designate a Required String Field in Your External Schema
 * Use an InfoPath Data Validation Rule to Create a Required String Field



SUMMARY
This step-by-step article describes how to create required (that is, &quot;cannot be blank&quot;) string fields in your InfoPath form.

back to the top

Introduction
If you create your own data source in InfoPath, you can designate a string field as a required field (that is, &quot;cannot be blank&quot;) by modifying the field's properties in the Data Source task pane. However, if you instead use an external schema for your form's data source, you can designate a string field as a required field in one of two ways:
 * You can create a simpleType element for the required field's type in the schema. This simpleType element contains a minLength restriction that is equal to or greater than 1.

-or-
 * If you cannot modify the schema, you can create a data validation rule in your InfoPath form.

The steps in this article describe each of these techniques that you can use to create a required string field on your form.

back to the top

InfoPath 2007

 * 1) In InfoPath, design a new blank form.
 * 2) In the Data source task pane, right-click the myFields group, and then click Add. The Add Field or Group dialog box appears.
 * 3) In the Name box, type ID. Click to select the Cannot be blank check box, and then click OK. Notice that the ID field appears in the Data source task pane with a red asterisk to indicate that it is a required field.
 * 4) Drag the ID field from the Data source task pane to your form.
 * 5) On the File menu, point to Preview, and then click Form.
 * 6) With the mouse pointer, pause on ID. Notice the screen tip &quot;Cannot be blank.&quot; This is the default screen tip for fields that are marked as required in the schema.

InfoPath 2003

 * 1) In InfoPath, design a new blank form.
 * 2) In the Data Source task pane, right-click the myFields group, and then click Add. The Add Field or Group dialog box appears.
 * 3) In the Field Name box, type ID. Under Validation, click to select the Cannot be blank check box, and then click OK. Notice that the ID field appears in the Data Source task pane with a red asterisk to indicate that it is a required field.
 * 4) Drag the ID field from the Data Source task pane to your form.
 * 5) On the File menu, point to Preview Form, and then click Default.
 * 6) With the mouse pointer, pause on ID. Notice the screen tip &quot;Cannot be blank.&quot; This is the default screen tip for fields that are marked as required in the schema.

back to the top

Create a custom schema file
In a text editor such as Notepad or in an XML editor, create the following schema. Then, save the schema as Customschema.xsd.               </xs:simpleType> </xs:schema> Notice that the FirstName field is typed with a simpleType element that is named &quot;myReqString,&quot; and &quot;myReqString&quot; has a restriction that the length must be at least one character.

InfoPath 2007
<ol> <li>Start InfoPath.</li> <li>Design a new form that uses Customschema.xsd for the primary data source. To do this, follow these steps: <ol style="list-style-type: lower-alpha;"> <li>On the File menu, click Design a Form Template.</li> <li>In the Design a Form Template task pane, click XML or Schema, and then click OK. The Data Source Wizard appears.</li> <li>Click Browse, select the Customschema.xsd file in the Open dialog box, click Open, and then click Next.</li> <li>Click No, and then click Finish to complete the wizard.</li></ol> </li> <li>Notice the fields in the Data source task pane. Notice that the FirstName field is marked with a red asterisk to indicate that the field cannot be blank. LastName is not marked with an asterisk. Therefore, it is not a required field.</li> <li>Drag the Employee group from the Data source task pane to your form, and then click Section with Controls.</li> <li>Test your form. To do this, follow these steps: <ol style="list-style-type: lower-alpha;"> <li>On the File menu, point to Preview, and then click Form. The form opens in preview mode.</li> <li>Notice that only the First Name text box is displayed with a red asterisk. This red asterisk indicates that the field is required and cannot be blank.</li> <li>With the mouse pointer, pause on First Name. Notice the screen tip &quot;Cannot be blank.&quot; This is the default screen tip for fields that are marked as required in the schema.</li></ol> </li></ol>

InfoPath 2003
<ol> <li>Start InfoPath.</li> <li>Design a new form that uses Customschema.xsd for the primary data source. To do this, follow these steps: <ol style="list-style-type: lower-alpha;"> <li>On the File menu, click Design a Form.</li> <li>In the Design a Form task pane, click New from Data Source. The Data Source Setup Wizard appears.</li> <li>Select XML Schema or XML data file for the data source type, and then click Next.</li> <li>Click Browse, select Customschema.xsd in the Open dialog box, and then click OK. Click Finish to complete the wizard.</li></ol> </li> <li>Notice the fields in the Data Source task pane. Notice that the FirstName field is marked with a red asterisk to indicate that the field cannot be blank. Because LastName is not marked with an asterisk, it is not a required field.</li> <li>Drag the Employee group from the Data Source task pane to your form, and then click Section with Controls.</li> <li>Test your form. To do this, follow these steps: <ol style="list-style-type: lower-alpha;"> <li>On the File menu, point to Preview Form, and then click Default. The form opens in preview mode.</li> <li>Notice that only the First Name text box is underscored with a red line. This red line indicates that the field is required and cannot be blank.</li> <li>With the mouse pointer, pause on First Name. Notice the screen tip &quot;Cannot be blank.&quot; This is the default screen tip for fields that are marked as required in the schema.</li></ol> </li></ol>

back to the top

Outlook 2007 or Outlook 2003
<ol> <li>Right-click the LastName field in the Data Source task pane, and then click Properties. The Field or Group Properties dialog box appears. Notice that the Cannot be blank option is disabled; this property is always disabled in the InfoPath user interface when your data source is an external data source. Click Cancel to dismiss the dialog box.</li> <li>Right-click the text box for the LastName field, and then click Text Box Properties.</li> <li>In the Text Box Properties dialog box, click Data Validation. The Data Validation dialog box appears.</li> <li>Click Add.</li> <li>Select is blank in the second condition list, type Last Name is a required field in the ScreenTip text box, and then click OK.</li> <li>Click OK to close the Data Validation dialog box, and then click OK to close the Text Box Properties dialog box.</li> <li>Test your form: <ol style="list-style-type: lower-alpha;"> <li>Preview the form.</li> <li>Notice that the Last Name text boxis now displayed with a red asterisk or underscored with a red line. This red asterisk or red line indicates that the field is required and cannot be blank.</li> <li>With the mouse pointer, pause on Last Name. Notice the custom screen tip &quot;Last Name is a required field.&quot; This is the custom screen tip that you typed for the data validation rule.</li></ol> </li></ol>

back to the top

Additional query words: IP2007 OL2007

Keywords: kbxml kbschema KB827004

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.