- In the Database window, click Forms under Objects.
- Click the New button on the Database window toolbar.
- In the New Form dialog box, double-click Form Wizard.
- In the first wizard dialog box, select a table or query from the list. For example, to create a Categories form that displays products for each category in a subform, select the Categories table (the "one" side of the one-to-many relationship).
Note It doesn't matter which table or query you choose first.
- Double-click the fields you want to include from this table or query.
- In the same wizard dialog box, select another table or query from the list. Using the same example, select the Products table (the "many" side of the one-to-many relationship).
- Double-click the fields you want to include from this table or query.
- When you click Next, if you set up the relationships correctly before starting the wizard, the wizard asks which table or query you want to view by. Using the same example, to create the Categories form, click By Categories.
- In the same wizard dialog box, select the Form With subform(s) option.
- Follow the directions in the remaining wizard dialog boxes. When you click Finish, Microsoft Access creates two forms, one for the main form and subform control, and one for the subform.
Create a subform and add it to another form
- Open the form that you want to add the subform to in Design view.
- Make sure the Control Wizards tool in the toolbox is pressed in.
- Click the Subform/Subreport tool in the toolbox.
- On the form, click where you want to place the subform.
- Follow the directions in the wizard dialog boxes.
- When you click Finish, Microsoft Access adds a subform control to your form. It also creates a separate form for the subform.
Add a form to another form to create a form with a subform
- Open the form that you want to use as the main form in Design view. This is usually a form based on a table or query on the "one" side of a one-to-many relationship.
- Make sure the Control Wizards tool in the toolbox is pressed in.
- Press F11 to switch to the Database window.
- Drag a form, table, or query from the Database window to the main form.
Create a form with two subforms
The main form has a one-to-many relationship with the first subform, and the first subform has a one-to-many relationship with the second subform, and the main form contains both the subform controls.
- In the Database window, click Forms under Objects.
- Click the New button on the Database window toolbar.
- In the New Form dialog box, double-click Form Wizard in the list.
- In the first wizard dialog box, select the table or query for the main form. For example, suppose you want to create a Customers form that has two subforms
— an Orders subform and an Order Details subform. Select the Customers table (the "one" side of the first one-to-many relationship). Note It doesn't matter which table or query you choose first.
- Double-click the fields you want to include from this table or query.
- In the same wizard dialog box, select the table or query for the first subform. Using the same example, select the Orders table (the "many" side of the first one-to-many relationship), and then double-click the fields you want to include from this table or query.
- In the same wizard dialog box, select the table or query for the second subform. Using the same example, select the Order Details table (the "many" side of the second one-to-many relationship), and then double-click the fields you want to include from this table or query.
- When you click Next, if you set up the relationships correctly before starting the wizard, the wizard asks which table or query you want to view by. Using the same example, to create the Customers form, click By Customers.
- In the same wizard dialog box, select the Form With subform(s) option.
- Follow the directions in the remaining wizard dialog boxes. When you click Finish, Microsoft Access creates a main form with two subform controls. It also creates two other forms, one for each subform.
Notes
- When you use a wizard to create a form with two subforms, Microsoft Access synchronizes the subforms by attaching an event procedure to the OnCurrent property of the first subform. You can copy and modify this event procedure if you want to synchronize more subforms on the same form. To see this event procedure, open the first subform in Design view, double-click the form selector, and then click the Build button next to the OnCurrent property.
- The Customer Orders form in the Northwind sample database is a form with two subforms. To view this form, point to Sample Databases on the Help menu, click either Northwind Sample Database or Northwind Sample Access Project, and then open the Customer Orders form in Design view.
Create a form with nested subforms
The main form has a one-to-many relationship with the first subform, and the first subform has a one-to-many relationship with the second subform, and the second subform is embedded in the first subform.)
- Create a form with a subform.
- In the Database window, click Forms under Objects.
- Click the New button on the Database window toolbar.
- In the New Form dialog box, double-click Form Wizard.
- In the first wizard dialog box, select a table or query from the list. For example, to create a Categories form that displays products for each category in a subform, select the Categories table (the "one" side of the one-to-many relationship).
Note It doesn't matter which table or query you choose first.
- Double-click the fields you want to include from this table or query.
- In the same wizard dialog box, select another table or query from the list. Using the same example, select the Products table (the "many" side of the one-to-many relationship).
- Double-click the fields you want to include from this table or query.
- When you click Next, if you set up the relationships correctly before starting the wizard, the wizard asks which table or query you want to view by. Using the same example, to create the Categories form, click By Categories.
- In the same wizard dialog box, select the Form With subform(s) option.
- Follow the directions in the remaining wizard dialog boxes. When you click Finish, Microsoft Access creates two forms, one for the main form and subform control, and one for the subform.
Note Select the Tabular (the equivalent of Form view) option when the wizard asks what layout you want for the subform.
- In Design view of the main form, select the subform control and click again inside the control t o select the form, just as you would if you opened the subform in Design view from the Database window.
- Do one of the following:
- Repeat step 1 to create the second subform by using the wizard.
- Drag a form, table, or query from the Database window to the subform. Microsoft Access creates another subform inside the first subform and creates a form for the subform.