|
Sub-Forms and Sub-Reports |
|
|
A subform (or a subreport) is a form that placed in the
body of an existing form (or report). The subform (or subreport) is usually
made to show some records. The records of the subform (or subreport) must
come from a table, a SQL expression, or a query.
|
Practical
Learning: Introducing Subforms
|
|
- Start Microsoft Access
- In the File Name text box, replace the name with College
Park Auto Repair3
- Click Create
- On the default table, double-click ID
- Type RepairOrderID and press Enter
- Right-click the Table1 and click Design View
- Set the name of the table to RepairOrders
- Click OK
- Complete the table with the following fields:
Field Name |
Data Type |
Field Size |
Format |
Caption |
Default Value |
RepairOrderID |
|
|
|
Repair Order ID |
|
CustomerName |
|
50 |
|
Customer Name |
|
Address |
|
60 |
|
|
|
City |
|
40 |
|
|
|
State |
|
40 |
|
|
|
ZIPCode |
|
20 |
|
ZIP Code |
|
Make |
|
50 |
|
|
|
Model |
|
50 |
|
|
|
CarYear |
Number |
Integer |
|
Year |
|
ProblemDescription |
Memo |
|
|
Problem Description |
|
TaxRate |
Number |
Double |
Percent |
Tax Rate |
0.0575 |
Recommendations |
Memo |
|
|
|
|
- Save and close the table
- On the Ribbon, click Create
- To create a new table, in the Tables section, click Table
- Double-click ID
- Type PartUsedID and press Enter
- Right-click the Table1 and click Design View
- Set the name of the table to PartsUsed
- Click OK
- Complete the table with the following fields:
Field Name |
Data Type |
Field Size |
Format |
Caption |
PartUsedID |
|
|
|
Part Used ID |
RepairOrderID |
Number |
Long Integer |
|
RepairOrderID |
PartName |
|
50 |
|
Part Name |
UnitPrice |
Number |
Double |
Currency |
Unit Price |
Quantity |
Number |
Byte |
|
|
- Save and close the table
- On the Ribbon, click Create
- In the Tables section, click Table
- Double-click ID
- Type JobPerformedID and press Enter
- Right-click the Table1 and click Design View
- Set the name of the table to JobsPerformed
- Click OK
- Complete the table with the following fields:
Field Name |
Data Type |
Field Size |
Format |
Caption |
JobPerformedID |
|
|
|
Job ID |
RepairOrderID |
Number |
Long Integer |
|
RepairOrderID |
JobPerformed |
|
100 |
|
Job Performed |
JobPrice |
Number |
Double |
Currency |
Job Price |
- Save and close the table
To have a meaningful subform (or subreport), there
must be a relationship between the record source (table or query) of the
subform (or subreport) and the record source (table or query) of the
subform (or subreport).
Practical
Learning: Creating a Relationship
|
|
- On the Ribbon, click Database Tools
- In the Relationships section, click Relationships
- On the dialog box, double-click Parts Used
- Double-click RepairOrders
- Double-click JobsPerformed
- Click Close
- In the RepairOrders table, drag RepairOrderID and drop it on top
of RepairOrderID on the PartsUsed table
- In the Edit Relationship dialog box, click Enfore Referential
Integrity
- Click the other two check boxes
- Click Join Type...
- Click the 2: radio button
- Click Create
- Create the same type of relationship from the RepairOrderID of the
RepairOrders table to the RepairOrderID of the JobsPerformed table
- Close the Relationships window
- When asked whether you want to save, click Yes
A subform is primarily designed like a normal form. In
most cases, you should set its Default View to Continuous Forms
Practical
Learning: Creating a Subform
|
|
- On the Ribbon, click Create
- In the Forms section, click Form Wizard
- In the first page of the wizard, select PartsUsed in the combo box
- Click the Select All button
- Click Next
- In the second page of the wizard, click Tabular
- Click Next
- In the third page of the wizard, change the title to
sbfJobsPerformed
- Click Finish
- Right-click the title bar of the form and click Design View
- Double-click the button at the intersection of the rulers to
access the click Property Sheet
- In the Property Sheet, click Format
- Change the following properties:
Navigation Button: No
Dividing Lines: Yes
- Click the Form Footer bar
- In the Property Sheet, double-click Visible to set it to No
- Design the subform as follows:
- Save and close the form
- On the Ribbon, click Create
- In the Forms section, click Form Design
- Right-click the form and click Form Header/Footer
- To save the form, right-click its tab and click Save
- Set the name to sbfPartsUsed and click OK
- Double-click the button at the intersection of the rulers to
access the click Property Sheet
- In the Property Sheet, click All
- Change the following properties:
Record Source: Parts Used
Default View: Continuous Forms Navigation Button: No Dividing
Lines: Yes
- Click the Form Footer bar
- In the Property Sheet, double-click Visible to set it to No
- In the Tools section of the Ribbon, click Add Existing Fields
- From the Fields list, drag RepairOrderID and drop in the Detailt
section of the form
- Click its accompanying lable and press Delete
- Design the subform as follows:
- Save and close the form
Creating the Hosting Form
|
|
After creating a sub-form, you must create the form
that will host it. The form is a normal form whose Record Source has a
field that is related to the subform. To create the sub-form, you can use
a wizard.
Practical
Learning: Creating a Form
|
|
- On the Ribbon, click Create
- In the Forms section, click Form Design
- Right-click the form and click Form Header/Footer
- Click the button at the intersection of the rulers
- In the Property Sheet, click Data
- Set the Record Source to RepairOrders
- Save the form as RepairOrders
- Design the form as follows:
- From the Naviagation Pane, drag sbfPartsUsed and drop it in the
Parts Used section of the form
- From the Naviagation Pane, drag sbfJobsPerformed and drop it in
the Jobs Performed section of the form
- Complete the design of the form as follows:
- Save the form
- To preview it, right-click its tab and click Form View
- Create a record as follows:
- Close the form
A subreport also starts like a normal report. If you
plan to perform calculations on the subreport, you should (must) add the
Practical
Learning: Creating a Subform
|
|
- On the Ribbon, click Create
- In the Reports section, click Report Design
- Right-click the report and click Report Header/Footer
- To save the report, right-click its tab and click Save
- Set the name to sbrPartsUsed and click OK
- Design the report as follows:
- Save and close the report
- On the Ribbon, click Create
- In the Reports section, click Report Design
- Right-click the report and click Report Header/Footer
- To save the report, right-click its tab and click Save
- Set the name to sbrJobsPerformed and click OK
- Design the report as follows:
- Save and close the report
- On the Ribbon, click Create
- In the Reports section, click Report Design
- Right-click the report and click Report Header/Footer
- To save the report, right-click its tab and click Save
- Set the name to RepairdOrders and click OK
- Design the report as follows:
- Save the report
- Right-click the tab and click Print Preview
- Close the report
|
|