- The Business Problem
- Introduction to InfoPath
- An Abbreviated Case Study
- InfoPath Capabilities
- The InfoPath Interface
- Creating an InfoPath Form
- Conclusion
Creating an InfoPath Form
Now that I've described the components that make up an InfoPath form, let's look at one of several techniques that can be used to design a simple InfoPath form. In this example, we'll create a simple form that's connected to the Northwind sample database supplied with InfoPath. InfoPath provides several ways to accomplish each task. The instructions given here are based on the final version of InfoPath 2003.
Open InfoPath and the task pane, if necessary.
Select the Design a Form option from the drop-down list.
In the Design a Form task pane, choose the New from Data Source option (see Figure 2). This step opens the Data Source Setup Wizard.
Select the Database option and click Next.
On the next screen, click the Select Database button and navigate to the Northwind sample database. For example, the relevant version of the Northwind database is located at the following path on my machine:
After selecting the database, select the table(s) to use in the form. For this simple example, scroll down to the Suppliers table and select it.
In the next dialog box, deselect all columns except CompanyName, ContactName, and ContactTitle. You have options to add further tables, but for this example we'll just click Next (see Figure 3).
You have the option to design the query view or data view first. Select Query View and click Finish. A simple query view is created automatically; this view is functionally able to query the Access database (see Figure 4). However, we don't yet have a view to display the data returned by the query.
If the task pane isn't visible, press Ctrl+F1 to display it. From the task pane drop-down list, select the Views task pane. The pane shows that two views exist (see Figure 5): the query view that we've just seen, and the data entry view. Click the Data Entry option to switch to that view. The view is blank.
To create a basic data entry view, click Data Source on the task pane. This step switches to the data source task pane. Drag the CompanyName node to the form area. A repeating section is created, with a text box (intelligently named Company Name) inserted automatically. Drag the ContactName and ContactTitle nodes (from the dataFields) inside the repeating section. Named text boxes are created automatically for these features. InfoPath intelligently handles the field names so that they appear as discrete words on the view (see Figure 6).
Click Controls in the Data Source task pane to open the Controls task pane. Drag a button control to the form area, making sure that it's not inside the repeating section.
Right-click the Button control and select Button Properties.
On the General tab of the dialog box, select Submit from the Action drop-down list, and alter the label to read Submit (see Figure 7).
Accept the defaults in the next dialog box that opens; then click OK to accept the changes to the Button control's properties.
Now we can test the form. Click the Preview Form button on the toolbar, or press Alt+P. Switch to the Query view by choosing View, Query from the menu. Enter the text Exotic Liquids in the CompanyName text box and click the Run Query button. (Exotic Liquids is a company listed in the Northwind database.) The Data Entry view opens with the relevant contact information fields for Exotic Liquids containing the requested data (see Figure 8).
TIP
Press Ctrl+F1 to open the task pane.
Figure 2 Designing a new form from a data source.
C:\Program Files\Microsoft Office 2003\OFFICE11\SAMPLES\NORTHWIND.mdb
Figure 3 Fields in the Access Suppliers table.
Figure 4 The query view that InfoPath creates automatically.
Figure 5 The Views task pane.
Figure 6 Form with text boxes added.
Figure 7 Altering button properties.
Figure 8 Data returned from the query.
That's all there is to creating a very basic but functional InfoPath form. Of course, you can do much more to improve form layout, add validation that goes beyond what the W3C XML Schema can provide, and script custom functionality. But end users can create simple but functional forms like this very quickly.
NOTE
As mentioned earlier, serious use of InfoPath 2003 requires knowledge of XML and JScript or VBScript. Understanding of W3C XML Schema, XSLT, the XML DOM, and XPath will also be very useful to InfoPath developers.