The data editing form you created in the preceding sections is adequate for use by experienced users, but adding data entry validation and lookup lists for queries makes the form easier to use. You also are likely to be faced with the need to change the primary data source for the form. The following sections cover these three topics. Setting Local Data Validation RulesIf the schema for your form specifies XSD built-in datatypes of elements, such as decimal, int, boolean, date, or dateTime, InfoPath tests your query filter and data entry values for conformance to the requirements of the World Wide Web Consortium (W3C) XML Schema Part 2: Datatypes recommendation. XSD schema also can apply constraints to data values by facets, such as length, minLength, and maxLength for the string data type. Each datatype has its own set of facets. The built-in primitive and derived data types handle almost all Jet and SQL Server 2000 datatypes. (Jet's Hyperlink field data type is an exception; Jet Currency and SQL Server money fields convert to the decimal datatype.) Note You can read the W3C XML Schema Part 2: Datatypes recommendation at http://www.w3.org/TR/xmlschema-2/> InfoPath doesn't attempt to determine the dataType or other constraints, other than maxLength of queryFields and dataFields subelements. You could alter the schema(s) for your form to add dataType, but the process isn't simple. ADO Recordsets use attribute-centric, not element-centric, XML. The nodes that appear to be elements under the q:customers and d:customers nodes in the Data Source list are attribute name/value pairs. If you mark the Show Details check box, InfoPath reports the data type as simpleType, which corresponds to XSD's anySimpleType datatype. Schema1.xml (for q:customers) and Schema2.xml (for d:customers) specify string as the data type of all fields.
To review the differences between element- and attribute-centric XML, see "Gaining an XML Vocabulary," p. 944. InfoPath uses XML Path Language (XPath) 1.0 expressions to apply validation constraints to controls. Fortunately, you don't need to learn XPath syntax to add simple constraints, such as Jet's Required = Yes or Allow Zero Length = No. Adding constraints to numeric values is equally simple. As an example, do the following to require CustomerID and CompanyName values for new Customers records:
If you attempt to submit a form with a value that violates a validation rule, you receive an "InfoPath cannot submit the form because it has errors" message and a red dashed outline surrounds the offending text box or other control. The Data Validation dialog lets you create compound validation rules that are similar to Access's table-level validation. You can combine validation rules for the same or different fields with and/or logic by clicking the And button and selecting And or Or in the right-most list (see Figure 26.37). Figure 26.37. The Data Validation dialog lets you design compound validation rules that are similar to Access's table-level validation rules.
Tip Open the Section Properties dialog for a section, click the Display tab, click the Conditional Formatting button, and then click the Add button to open the Conditional Formatting version of the Data Validation dialog. This dialog lets you change the background color of the section, the font color of the control, and other display attributes when users violate a validation rule. Changing a Text Box to a Bound Drop-down ListInfoPath controls have a Change To context menu choice that emulates Access's Change To feature. You can change a bound text box to one of nine bound InfoPath controls. The most common change is from a text box to a drop-down list or date picker control for date or dateTime fields. At the risk of creating an extraordinarily long list, you can change the CustomerID text box of the query field to a drop-down list of CustomerID values populated by a secondary data source. HTML lists don't have the flexibility of Access combo boxes, so you can't type a value into the list's text element. However, InfoPath thoughtfully adds an empty value at the top of the list, so users can apply a query filter without specifying a CustomerID value. Creating the Secondary Data SourceCreating a secondary data source from a database is almost identical to creating the primary data source. For a drop-down list, you usually add only the field to which the text box is bound. To add the CustomerID field as a secondary data source for a drop-down list on the form, do this:
Replacing a Text Box with a Drop-down ListTo replace the CustomerID text box of the query section with the drop-down list and specify the list's row source, do the following.
The entire XPath expression for the list entries, which isn't visible fully in Figure 26.39, is /dfs:myFields/dfs:dataFields/d:Customers. The dfs: qualifier presumably represents "data field source." Tip If you want to display values from another field, such as CompanyName, instead of the primary key value, include the field when you create the secondary data source. Change the XPath reference to the other field (@CompanyName) in the Drop-Down List Properties dialog's Display Name text box. You must increase the width of the list to make the company names readable. Changing a Form's Primary Data SourceAs mentioned earlier in the chapter, changing an InfoPath 1.0 primary data source isn't as easy as changing secondary data sources. To change the path or filename for a Jet data source or change from the Jet to an SQL Server version of the data source, you must manually alter the manifest file in Notepad and then refresh the template file with the altered manifest file. The process is similar to the changes you made to the Currency data source in the earlier "Changing a Secondary Data Source" section. To change the location of a Jet primary data source, do the following:
If you don't explicitly overwrite the TemplateName.xsn file, you might find that the changes you made to manifest.xsf aren't reflected in the template file. Tip If you want to move the primary data source from Jet to an upgraded SQL Server 2000 database, create in a different folder a temporary template from the SQL Server data source and extract the manifest.xsf file. Copy the entire contents of each <adoAdapter> element and paste-replace the corresponding element in the original manifest.xsf file.
|