your image

How to Add a Subform to a Form in Access 2016

quackit
Related Topic
:- MS Access

How to Add a Subform to a Form in Access 2016

 

You can add a subform to a form to provide related data from a one-to-many relationship. This allows you to present many related records within a record.

A subform is a form that is nested inside of another form. It usually contains data that is relevant to the record that is currently open in the main form.

For example, you could have a form that displays an order, and a subform that displays each item within the order.

Or, you could have a form that displays a band, with a subform that displays each album that band has released.

Here's another example. We'll add a subform to a form that contains information about countries. The subform will display the cities within each country.

  1. Open the Form

    In the left Navigation Pane, right-click on the form and select Design View from the contextual menu.

  2. Expand the Controls Toolbar

    Locate the Controls group on the Design tab in the Ribbon.

    Click the little down-arrow to expand the list of available form controls.

  3. Select the Subform Option

    Click the Subform/Subreport icon to select it.

    Then click in the form, in the location that you'd like the subform to be displayed.

    This launches the SubForm Wizard.

    You can hover over each icon to see which control it represents.

  4. Select the Data Source to use for the SubForm

    You have the option of basing your subform on a table or query, or on an existing form.

    In this example, we'll select Use existing Tables and Queries.

    Once you've selected the option, click Next >.

  5. Select the Fields

    If you selected Use existing Tables and Queries, you will now be asked to select the fields to use in the subform.

    Select the table or query from the drop-down list.

    On the left pane, select each field that you need on the subform, then click the little > button to move it across to the right pane.

    You can select fields from more than one table or query. Simply select another table/query from the drop-down when you're done with the first one.

    Once done, click Next >.

    You can also double-click a field to move it to the other pane.

    You can also use the >> button to move all fields across.

  6. Choose the Linking Field

    There needs to be a field that links the main form and its subform. This is typically an ID field or similar.

    If you've previously set up a relationship for the tables, then Access will guess which field to use based on the primary key and foreign key of the relationship.

    At this part of the wizard, Access gives you the opportunity to choose your own field or select another one from the list provided.

    For this example we leave it at the field that Access guessed.

    Once you've selected a field, click Next >.

    Technically, there doesn't need to be a linking field. You could select None.

    However, you'll probably end up with a subform displaying data that has nothing to do with the current record. All records will display the same subform with the same data.

  7. Name the Subform

    Enter a name for the subform.

    Click Finish.

  8. The Subform in Design View

    The subform is now added to the form, at the location you clicked at step 3.

    In Design View it appears as a big embedded form.

  9. Modify if Required

    You may need to make some minor adjustments to the formatting. For example, you may need to adjust label's position, colors, font weight, etc.

    Switch to Layout View and back to Design View to modify as required.

  • The Finished Subform

    Now switch to Form View to see how it's displayed to the user.

    The main form appears, with the subform embedded within it. The subform is displayed in Datasheet view, just like a regular table or query results.

    As you navigate through the records in the main form, the data in the subform updates.

    Subforms in Datasheet View are sometimes referred to as subdatasheets.

    Datasheet View is not the only view that a subform can be displayed in. You can use the Property Sheet to change the default view to Single Form, Continuous Forms, or Split View.

    To do this, look for the Default View property.

  • Saving the Subform

    When you save the form, the subform is saved as a separate form.

  • Viewing the Subform as a Standalone Form

    The subform appears in the Navigation Pane just as any other form does — after all, it's just another form.

    When you open it, it will probably open in Datasheet View (assuming that's the view that you've chosen for the subform).

    You can always change its default view (via the Property Sheet), however, be aware that this will also affect the way the subform is displayed within the other form.

    When displayed as a subform (within another form), it only displays the data that's relevant to the current record of its parent form. However, when opened as a standalone form, it displays all data

Comments