Summary: Learn how to create a file attachment control that lets users attach documents to their forms and how to customize controls by changing their property settings. In addition, use advanced InfoPath controls, including the master/detail control and the choice control, to manage the way that data is displayed in a form. Learn how to design filters so that users can filter data in a form. (8 printed pages)

Contents

Scenario

Employees in the sales department at Contoso Corporation have requested that the IT department add several new features to their existing sales report form. In particular, they want to:

Attach documents, worksheets, and other files to their forms.

Efficiently manage large amounts of data in the form.

Have the option to include either a customer name or a customer ID section.

Filter customers based on location.

The IT department plans to update the existing form by adding several new controls. These controls allow sales representatives to work more efficiently.

Lab Objective

In this lab you learn how to do the following:

Level 200

Add a file attachment control to the form.

Customize the file attachment control by changing its properties.

Level 300

Add a master/detail control to the form, so that users can better manage data in the form.

Add a choice control to the form, so that users can replace one option with another.

Filter data in the form.

Level 200 Exercises

Exercise 1: Add a File Attachment Control to the Form

When filling out sales report forms sales representatives often want to attach supplementary files, such as Microsoft Office Word 2003 documents, to their forms. As a form designer, you can add a special type of control to your form, called a file attachment control, which allows users to attach files to their form. In this exercise, you learn how to add this control to your form and specify the type of file that you want users to attach.

To add a file attachment control to the form

Start InfoPath.

In the Fill Out a Form dialog box, click Design a Form.

In the Design a Form task pane, click On My Computer.

In the Open in Design Mode dialog box, locate the folder where you installed the training files, and then double-click the Lab 4 folder.

Select Lab4Template200.xsn, and then click Open. The Contoso Sales Report form opens in design mode.

In the Design Tasks task pane, click Controls.

Place your cursor below the repeating section at the bottom of the form.

Under Insert controls, click File Attachment.

Now that you have added the file attachment control to your form, you can specify the type of file you want to allow users to attach.

To limit the type of file attachments

In the form, double-click the file attachment control.

In the File Attachment Properties dialog box, on the Data tab, select the Allow the user to attach only the following file types check box.

In the box underneath the check box, type doc, and then click OK. This feature limits the types of files that users can attach to Word (.doc) files.

Preview your form to test the file attachment control.

To preview the form

On the Standard toolbar, click Preview Form.

In the form area, click the file attachment control.

In the Attach File dialog box,browse to any folder containing a Word document and click it.

Although other files may exist in this folder, only Word (.doc) files are visible.

To attach the file to the form, click Insert.

To open the Word document from within the form, right-click the file attachment, and then click Open.

To close the preview window and return to design mode, click Close Preview on the Standard toolbar.

Exercise 2: Customize a Control's Properties

If you want to customize the behavior and appearance of a particular control, you can change its property settings. The following exercises demonstrate how to specify a character limit for a text box by changing the properties for that text box. The exercises also show how to change the size for several controls at once and customize menu commands associated with a repeating table control.

To limit the number of characters in a text box

With the form still open, double-click the Units Sold text box in the repeating table.

To return to design mode, click Close Preview on the Standard toolbar.

While you can set the properties for a single control, you can also specify certain properties, including size, padding, margins, and alignment settings, for several controls at once.

To change properties for multiple controls at once

In the repeating table, click the Name text box control, and then hold down CTRL and click each remaining control in the table.

On the Format menu, click Properties.

In the Properties (Multiple Selection) dialog box, type 1 in the Width box, change the unit of measure from % to in, and then click OK.

Each control in the repeating table is now 1 inch wide.

You can customize the menu commands that sales representatives use to add or remove rows in the repeating table. By default, users interact with these menu commands by clicking a shortcut menu button in the upper-left corner of the table. However, by adding an additional access point for these commands, you can make your form more flexible. In the next example, you add a custom button, called Insert New Item, to the Form toolbar.

To customize menu and toolbar commands for a repeating table

Double-click the Repeating Table label below the table on the form.

In the RepeatingTableProperties dialog box, on the Data tab, click Customize Commands.

The Table Commands dialog box appears with Insert selected in the Action list.

In the Location for the command list, select the Form toolbar check box.

In the Command name box, change the default text to Insert New Item, and then close all open dialog boxes.

On the Standard toolbar, click Preview Form.

To test your changes, place your cursor in the Name box in the repeating table.

To insert a new row in the table, on the Form toolbar, click Insert New Item.

To return to design mode, on the Standard toolbar, click Close Preview.

Level 300 Exercises

Exercise 1: Add a Master/Detail Control to the Form

Contoso wants its sales representatives to specify not only which products they sold, but also the parts that belong to each of those products. In the next exercise, you establish a master/detail relationship between two repeating tables. By setting up this type of relationship, you ensure that related parts information appear in a detail control whenever a sales representative selects an item in the master control.

To create the master control

Start InfoPath.

In the Fill Out a Form dialog box, click Design a Form.

In the Design a Form task pane, click On My Computer.

In the Open in Design Mode dialog box, locate the folder where you installed the training files, and then double-click the Lab 4 folder.

Select Lab4Template300MD.xsn, and then click Open.

The Contoso Sales Report form opens in design mode.

Double-click the Repeating Table label below the Units Sold table on the form.

In the Select a Field or Group dialog box, click the unitName field in the item group, and then click OK.

Click Select XPath next to the Key field (detail) box.

In the Select a Field or Group dialog box, click the unitNameReference field in the Part group, and then click OK.

On the Standard toolbar, click Preview Form.

To test the master/detail relationship, click on different rows in the Units Sold table. Notice how the information in the Parts belonging to the unit table changes based on your selection in the Units Sold table.

To return to design mode, click Close Preview on the Standard toolbar.

Exercise 2: Add a Choice Control to the Form

Choice controls allow users to replace one section with another in a form. For example, in the sales report form, you can let sales representatives choose to designate customers either by name or by numeric ID. In the following exercise, you learn how to create this type of control.

To create a choice control

With the form still open, delete the Customer Name label and text box.

If it's not already there, place your cursor above the Units Sold repeating table.

On the Insert menu, click More Controls.

Under Insert controls, click Choice Group.

In the control labeled Choice Section (default), type Customer Name:, and then insert a text box next to that text.

In the control labeled Choice Section, type Customer ID:, and then insert a text box next to that text.

Double-click the Choice Section (default) label.

In the Field or group name box in the Choice Section Properties dialog box, replace the default text with CustomerName, and then click OK.

Double-click the Choice Section label.

In the Field or group name box in the Choice Section Properties dialog box, replace the default text with CustomerID, and then click OK.

On the Standard toolbar, click Preview Form.

To test the choice control, move your pointer over the Customer Name text box.

When a shortcut menu button appears, click it, and then on the shortcut menu, click Replace with CustomerID.

The default section, Customer Name, is replaced with an alternative section, Customer ID.

Exercise 3: Add a Filter to the Form

In the next exercise, learn how to set up your form so that sales representatives can filter customers by location.

To add a filter

Start InfoPath.

In the Fill Out a Form dialog box, click Design a Form.

In the Design a Form task pane, click On My Computer.

In the Open in Design Mode dialog box, locate the folder where you installed the training files, and then double-click the Lab 4 folder.

Select Lab4Template300Filter.xsn, and then click Open.

The Contoso Regional Sales Report form opens in design mode.

Double-click the Repeating Table label below the repeating table in the form.

In the Repeating Table Properties dialog box, click the Display tab.

Under Filter, click Filter Data.

In the Filter Data dialog box, click Add.

Under Display data that meets the following conditions in the Specify Filter Conditions dialog box, in the third box, click Select a field or group.

In the Select a Field or Group dialog box, double-click regionFilter.

This field corresponds to the list control in the form.

To add an additional filter condition, click And.

You now have a second filter condition.

In the box in the first condition that is furthest to the right, change and to or.

In the second row, click on first box, and then click Select a field or group.

In the Select a Field or Group dialog box, double-click regionFilter.

Again, this field corresponds to the list control in the form.

Click on the third box, and then select Type Text.

Type Show All.

Click OK three times to close all open dialog boxes.

On the Standard toolbar, click Preview Form.

To test the filter, change the value in the list, and then observe the data in the repeating table.

Conclusion

In the first set of exercises, you learned how to create a file attachment control that lets users attach documents to their forms. You also learned how to customize controls by changing their property settings.

In the second set of exercises, you used advanced InfoPath controls, including the master/detail control and the choice control, to manage the way in which data is displayed in a form. You also learned how to design filters so that users can filter data in a form.

Was this page helpful?

Your feedback about this content is important.Let us know what you think.