• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL

Chapter 13. Designing Custom Multitable ... > Creating a Subform Using the Subform...

Creating a Subform Using the Subform/Subreport Wizard

The frmPersonnelActionsEntry form needs a subform in which to view the history of personnel actions for the employee displayed in the main part of the form. Access 97's new Subform/Subreport Wizard makes it possible for you to create a new subform at the same time that you add the subform field to the main form or, as in this example, a page in a Tab control. To do so, follow these steps:

Click the Design View button on the toolbar if the frmPersonnelActionsEntry form isn't already in Design view.

Click the Control Wizards button to enable the Control Wizards if the button isn't already down.

Click the second tab of the Tab control to bring its second page to the front. Click the Subform button in the Toolbox, and then click at the top-left corner of the second tab control page. Access displays the first dialog of the Subform/Subreport Wizard.

You can use this wizard either to create a new subform based on a table or query or to insert an existing subform (see Figure 13.58). (You learn how to insert an existing form as a subform later in the section "Creating and Using Continuous Forms." For this exercise, select the Table/Query option, and click Next to reach the second dialog.

The Subform/Subreport Wizard asks you to indicate which table or query the new subform is based on and which fields appear in the subform (see Figure 13.59). Select Query: qryPersonnelActionsSubform in the Tables and Queries drop-down list. To expedite field selection, click the >> button to copy all of the fields to the Selected Fields list. Select the paComments field in the Selected Fields list, and click the < button to remove this field from the list. Click Next to reach the third dialog.

Figure 13.58. Choosing whether to use an existing form as the subform or to use a table or query to create a new subform.

Figure 13.59. Selecting the data source and fields for the new subform.

The wizard now asks you to specify the link between the main form and the subform. You may select from a list of possible relationships that Access has determined, or define your own link. Click the Define my own option, and the Wizard dialog changes to show four drop-down list text boxes (see Figure 13.60).

In the upper Form/Report Fields list, select paID as the linking field; in the upper Subform/Subreport Fields list, also select paID as the linking field. Click Next to go to the fourth and final dialog of the wizard.

Type sbfTest as the name of this new subform, and click Finish to complete the subform's specifications (see Figure 13.61). Access creates and saves the new form; it inserts the completed subform into the subform field on the main form and sizes the subform field to accommodate the new subform (see Figure 13.62). The text you entered for the subform's name is assigned to the label for the subform. The subform itself is saved under the same name.

Figure 13.60. Defining the link between the main form and the subform.

Figure 13.61. Entering a name for your new subform.

Click the Form View button on the toolbar to check the appearance of the new subform. Your form appears as shown in Figure 13.63.

As you can see from Figure 13.63, the Subform/Subreport Wizard always creates new subforms with Datasheet view. In many cases, this is acceptable—or even desirable. For the frmPersonnelActionsEntry form, however, a better view of the data can be achieved with a tabular continuous form view of the data. The following sections explain the advantages of a tabular continuous form and guide you through the steps necessary to create such a form and insert it as a subform into the main form.

Close the frmPersonnelActionsEntry form by clicking the Close window button. Click No when Access asks if you want to save changes to the form's design.



Not a subscriber?

Start A Free Trial

  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint