Lab 4: Working with Controls in InfoPath 2003

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

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. 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. (7 printed pages)

Microsoft Corporation

April 2004

Updated August 2007

Applies to: Microsoft Office InfoPath 2003

  • Contents

  • Scenario

  • Lab Objective

  • Level 200 Exercises

  • Level 300 Exercises

  • Conclusion

  • Additional Resources

Download the odc_INF03_Labs.exe sample file.

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 perform the following tasks:

  • 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: Adding a File Attachment Control to the Form

When filling out sales report forms, sales representatives frequently 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 enables 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

  1. Start InfoPath.

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

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

  4. 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.

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

  6. In the Design Tasks task pane, click Controls.

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

  8. Under Insert controls, click File Attachment.

  9. 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

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

  2. 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.

  3. 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.

  4. Preview your form to test the file attachment control.

To preview the form

  1. On the Standard toolbar, click Preview Form.

  2. In the form area, click the file attachment control.

  3. 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.

  4. To attach the file to the form, click Insert.

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

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

Exercise 2: Customizing 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 show you 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

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

  2. In the Text Box Properties dialog box, click the Display tab.

  3. Under Options, select the Limit text box to check box, specify 4 characters, and then click OK.

  4. On the Standard toolbar, click Preview Form.

    The form opens in a new window.

  5. To test your changes, in the Units Sold box, type 12345.

    The text box accepts only 4 characters.

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

Although 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

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

  2. On the Format menu, click Properties.

  3. 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

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

  2. 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.

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

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

  5. On the Standard toolbar, click Preview Form.

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

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

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

Level 300 Exercises

Exercise 1: Adding 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

  1. Start InfoPath.

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

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

  4. 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.

  5. Select Lab4Template300MD.xsn, and then click Open.

    The Contoso Sales Report form opens in design mode.

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

  7. In the Repeating Table Properties dialog box, click the Master/Detail tab.

  8. Under Master/detail settings, click Set as master.

  9. In the Master ID box, type master1.

You now have a master control. In the next procedure, you designate a detail control. This control displays the parts associated with selected items in the master control.

To create the detail control

  1. Double-click the Repeating Table label below the Parts belonging to the unit table.

  2. In the Repeating Table Properties dialog box, click the Master/Detail tab.

  3. Under Master/detail settings, click Set as detail.

  4. In the Link to master ID list, click master1.

  5. Under Master/detail relationship, click By key field.

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

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

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

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

  10. On the Standard toolbar, click Preview Form.

  11. To test the master/detail relationship, click 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.

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

Exercise 2: Adding 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

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

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

  3. On the Insert menu, click More Controls.

  4. Under Insert controls, click Choice Group.

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

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

  7. Double-click the Choice Section (default) label.

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

  9. Double-click the Choice Section label.

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

  11. On the Standard toolbar, click Preview Form.

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

  13. 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: Adding 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

  1. Start InfoPath.

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

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

  4. 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.

  5. Select Lab4Template300Filter.xsn, and then click Open.

    The Contoso Regional Sales Report form opens in design mode.

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

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

  8. Under Filter, click Filter Data.

  9. In the Filter Data dialog box, click Add.

  10. 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.

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

    This field corresponds to the list control in the form.

  12. To add an additional filter condition, click And.

    You now have a second filter condition.

  13. In the box in the first condition that is rightmost, change and to or.

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

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

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

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

  17. Type Show All.

  18. Click OK three times to close all open dialog boxes.

  19. On the Standard toolbar, click Preview Form.

  20. 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 how data is displayed in a form. You also learned how to design filters so that users can filter data in a form.

Additional Resources

For more information about InfoPath, see the following resources: