Professional Documents
Culture Documents
COMM 335 - Winter 2019 Term 1: Tutorial 4: Microsoft Access - Building Forms and Subforms
COMM 335 - Winter 2019 Term 1: Tutorial 4: Microsoft Access - Building Forms and Subforms
1) build a main form with a subform for viewing and entering data; and
2) add a calculated control to a form.
You should download the sample database, comm335_T4.accdb, from the UBC Canvas as the
foundation to create and test forms in this tutorial.
A subform is a form within a form. The primary form is called the main form, and the form within
the form is called the subform. A form/subform combination is often referred to as a hierarchical
form, a master/detail form, or a parent/child form.
Subforms are especially effective when you want to show data from tables or queries with a one-to-
many relationship. For example, you could create a form with a subform to show data from a
Customer table and a Reservation table. The data in the Customer table is the "one" side of the
relationship. The data in the Reservation table is the "many" side of the relationship — each customer
can make more than one reservation.
The main form and subform in this type of form are linked so that the subform displays only records
that are related to the current record in the main form.
Demonstration:
Create a form to show all movies/videos with their rental information (as shown below).
Form
View
Rental
Subform in
Tabular format
Design
View
Movie Main
form in
Link Master Field
Columnar
format
from tblRental table from tblCopy table Calculated Field Calculated Control
in query in form
Key Steps:
a. Create two queries, one for the main form and another for the subform, to view all
movies/ videos with their rental records. (See note below.)
(Note: To save the time, please use the two queries, qryMovieRentalMain and
qryMovieRentalSub, that have been created for you.)
b. Add a calculated field to the query, qryMovieRentalSub, to calculate the Duration of the
rental, i.e. Duration: [DateIn]-[DateOut]. Insert this field after [DateIn] field. Test the
query. Does it work?
2. View your data by qryMovieRentalMain so that you can see the main form and
subform.
3. Select the Tabular1 layout (i.e. Continuous Forms View) for the subform.
1. Update the form header and form caption to display “Movie Rental Form”.
2. Delete the subform title. Adjust the width of the subform and the textbox size.
3. Set “Allow Additions” of the form property to “No” for both main form and subform
so that no new records can be added.
4. Remove the navigation buttons in the subform. (Update the form property of the
subform.)
5. Lock all the fields in the main form so that they are not editable.
6. Disable all the fields in the main form so that they cannot be selected for editing.
Disabled
Locked
1
“Tabular” is the layout you select when you create the form and subform. In the Form property sheet, it will be named
as “Continuous Forms View” in the Default View property.
2. Why do we want to disable and lock the Movie/Video fields in the main form?
3. What are the differences between “Record Source” and “Control Source”?
4. What are the differences between “Bound Control” and “Unbound Control”?
5. What are the differences between the Tabular layout and Datasheet layout?
Add a calculated control in the Movie Rental Subform (frmMovieRentalSub) to show the
Charge of each rental, i.e. [Duration] * [Rate] * (1-[Discount]).
Key Steps:
a. Close the Movie main form (frmMoveiRentalMain).
b. Open the Rental subform (frmMovieRentalSub).
c. Add a textbox to the Rental Subform (frmMovieRentalSub). (Do you notice that it is an
Unbound Control?)
Unbound
control
Calculated
control
e. Switch to Form View to check if the expression is correct. Modify the expression if you
see “#Name?” displayed in the Charge textbox.
f. Remove the label of the new textbox (in the Details section) and add a new label,
“Charge”, in the form header (as shown above) and align it with other labels.
Questions:
6. What are the differences between “Bound Control” and “Calculated Control”?
7. Are there any other ways to add the Charge field to the form?
- end of document -