Tips for Designing Data-Bound InfoPath Forms

InfoPath has an intuitive user interface, but some operations don't become evident until your users design themselves into a corner. Don't send your data down the primrose path; recommend that your InfoPath designers follow these tips for forms that display data and update tables:

Use a single view for query and data-entry operations. InfoPath Beta 2's default query and data-entry view will probably confuse users. Minimize the number of query-field textboxes to keep the query section as compact as possible and save room for a data-entry section on the same page. A single-record parent table view usually needs a textbox for the primary key field value only. You can't use % or * wildcards in InfoPath queries, so searching names and addresses usually isn't practical. (InfoPath queries use column value comparisons, not SQL statements, so filter is a more appropriate description than query).

Provide dropdown lookup lists that translate primary key codes to recognizable names. Create a static XML file or ADO query/view that contains only primary key and name values, add it as a secondary data source, and change the query textbox to a dropdown list bound to the secondary data source. (The Edit menu has a Change To choice for controls.) Set the dropdown list's value property to the primary key and the name property to the name column. Access 2002+'s export to XML feature makes creating static XML files from Jet queries or SQL Server views easy.

Don't change primary data sources in midstream. It's easy to change secondary data sources, but InfoPath wants primary data sources that are cast in concrete. Verify that column properties, such as Jet's Allow Zero Length or SQL Server's Allow Nulls, are correct because these values control the Cannot Be Blank property of bound textboxes. Changing the server name or moving from Jet to SQL Server as the primary data source, or altering the membership of queryFields and dataFields groups isn't a piece of cake.

Edit manifest.xsf in Notepad to alter the primary data source. If you must change the data source for a form in which you have a substantial design investment, here's the drill:

  1. Choose File | Extract Form files to extract the solution's archived files to modify into its folder, then close InfoPath.
  2. Create a temporary InfoPath solution in a new folder and use the Data Source Wizard to define the modified primary data source. You can add fields, change database names, or migrate from Jet to a corresponding (usually upsized) SQL Server database, but removing fields that have bound controls causes problems.
  3. Save the temporary solution and Choose File | Extract Form files to extract the archived files to the same folder.
  4. Open manifest.xsf in Notepad and copy the entire ... element (including the command text) to the clipboard.
  5. Repeat steps 2 and 3 for the solution you're modifying, except paste-replace the ... element you're modifying.
  6. If the manifest has more than one element, repeat steps 3 and 4 for each instance.
  7. Save the modified manifest.xsf file and close Notepad.
  8. In Windows Explorer, right-click on the modified manifest.xsf file and choose Design to open InfoPath from the manifest instead of the solution file.
  9. Test the modified manifest file and alter your form design as necessary to accommodate the data source changes.
  10. Choose File | Save As to overwrite the solution file with the changes, then extract the individual files again to make sure all files are up-to-date.
  11. If you need to change only a Jet file location or SQL Server instance name, you can skip steps 2 through 7, edit the connection string in manifest.xsf, then finish the process with steps 8 through 10.

Add read-only textboxes to store key values that synchronize dropdown lists. Replacing a textbox with a dropdown list doesn't work for data-entry fields. Regardless of the primary key value the query returns, the dropdown list displays the first list member. To solve this problem, mark the Read Only checkbox of the textbox's properties dialog's Display page, and add an adjacent dropdown list bound to the same dataField element. InfoPath complains with an "i" information screen tip that the "[c]ontrol stores duplicate data." You can ignore the warning safely (see Figure 2).

Format and right-align textboxes for currency and percent values. The textbox properties dialog's Data page has a format button that opens a dialog for choosing number, currency, or percentage formats and decimal places. The Display page has a dropdown list for left, center, and right alignment of data within the textbox.

Keep static XML secondary data sources up-to-date with InfoPath's Resource Manager. Substitute new XML document versions of the same name for secondary data sources:

  1. In design mode, choose Tools | Resource Manager to open the eponymous dialog and click Add to open the Add File dialog.
  2. Navigate to and double-click the updated XML file.
  3. Accept the Replace the Existing File option and click on OK to update the solution file.

Don't use SQL Server's real or Jet's Single data type with numeric XPath expressions. The real and Single (dt:type="r4") data types are four-byte floating-point values that represent some integers as 0.0000001 less than or greater than the actual numeric value that appears in a bound textbox. Examples are 5.0000001E-2 for 0.05 and 5.9999999E-2 for 0.06. If your fields contain values of this type, XPath expressions usually return 1.#QNAN; NAN is an abbreviation for Not A Number.

Watch out for null date values in SOAP response documents. If your ASP.NET XML Web services return serialized objects with dateTime fields, InfoPath's Beta 2 DatePicker control misinterprets Microsoft's serialization of a null date value (0001-01-01T00:00:00.0000000-08:00 for Pacific Time.) The DatePicker control translates this value to random dates in the early 1930s. Watch for a fix or workaround for this problem in InfoPath's release version.