Share this Page URL

Chapter 8. Adding Features and Function ... > Using a Subform to View Related Data - Pg. 278

Adding Features and Function to Forms 8. Click OK in the Conditional Formatting dialog box. 278 Using a Subform to View Related Data Viewing related data is one of the main purposes of a form. You can base a form on a query that retrieves related records from two or more tables. In Chapter 7, the Form Wizard used a command button to link the CampaignInformation form and the Expenses form. Another way to view related data on a form is to add a subform to a main form. Often, the main form displays records from a table on the one side of a one-to-many relationship, and the subform displays related records from the table on the many side of the relationship. Dis- playing a subform as a datasheet lets you view a number of related records very easily. In this section, we'll add a subform to the Tasks form that we designed in Chapter 7. The subform will display any comments entered about the status and work involved in completing the task that's displayed in the main form. You can add a subform using the Subform Wizard, one of the control wizards available in the toolbox. In the following steps, however, we'll add the subform ourselves and set the properties that link the subform and the main form together. The subform we'll add is named Comments. The form contains fields from the Comments table, which is a table on the many side of a one-to-many relationship with the Tasks table. If you want, open the form in Design view to see how we designed it. Add a subform to a main form 1. In the Database window, select the Tasks form, and then click Design. You'll probably need to increase the size of the form's Detail section to make room for the subform. You can use the mouse to resize the section by dragging or change the section's