Professional Documents
Culture Documents
COMM 335 - Winter 2019 Term 1: Tutorial 6: Microsoft Access - Building Combo Boxes and Compacting Database File
COMM 335 - Winter 2019 Term 1: Tutorial 6: Microsoft Access - Building Combo Boxes and Compacting Database File
Tutorial 6: Microsoft Access - Building Combo Boxes and Compacting Database File
1) create a (Type I) combo box to look up the values from a table/query and add the selected value
to a record;
2) create synchronized combo boxes; and
3) compact the database file.
You should download the sample database, comm335_T6.accdb, from the UBC Canvas as the
foundation to build and test the combo boxes in this tutorial.
A combo box is a list of values from which users can select a single value. In the last tutorial, you have
learnt how to create combo boxes to find a record on a form and update/add a record with
predefined values. In this tutorial, we will look at how to use a combo box to look up a value from a
table/query and store the selected value in a field.
Where will the rows for the list come from? (Row Source)
When a user selects an item in the combo box, what will Access do with that value?
(e.g. Store that value in a field.)
Type III
Type I
Type II
Create a new form New Rental Form and build two combo boxes for the purpose of adding a
new video rental contract for a customer. Sort the combo box entries in Ascending order.
Type I
Key Steps:
a. Create the form using the query, qryNewRental that has already been created for you.
Choose the Columnar layout and save the form as frmNewRental.
b. Add a form header, e.g. “New Rental Form”, but don’t worry about the field alignment
and tab order for the time being.
c. Set “Data Entry” of the form property to “Yes”. (What do you see when the form opens?
Don’t forget this step!)
d. Select Design Combo Box control. Click where you want to place the combo
box.
e. In the Combo Box wizard dialog box, select the 1st option “I want the combo box to get
the values from another table or query”. Click Next.
f. Choose the table tblCustomer (Row Source for this combo box.) Click Next.
g. Choose the field(s) that you want to display in the combo box, i.e. Last Name and First
Name (the primary key MemberNo field is selected automatically as this is the value that
will be stored in a new record). Click Next.
h. Select the sort order (Ascending) for Last Name and First Name fields. Click Next.
i. Notice that the “Hide the key column” is checked. Click Next.
j. Select “Store that value in this field” and choose “tblRental.MemberNo”, and then
click Next. (Don’t choose tblCustomer.MemberNo. Do you know why? Refer to the
diagrams below. Without the combo box, how do you enter MemberNo into a new rental
record?)
k. Provide a meaningful label for the combo box, e.g. “Search by Customer Name:”.
Row Source
Question:
1. Which table will be updated as a result of adding/updating a record using this combo box?
Practice:
Add a combo box in the New Rental Form (frmNewRental) to search a video by Copy No.
(Which table(s) and field(s) should be selected to build the combo box?)
Modify the New Reservation Form (frmNewReservation) and add two combo boxes. The user
should be able to use the 1st combo box to select movie category, and use the 2nd combo box to
select movie title from a list of movies that belong to the category selected in the 1st combo box.
Key Steps:
a. Open the New Reservation Form (frmNewReservation) in design view.
b. Add a combo box to search for Category (choose Type I combo box, display
CategoryDesc from tblCategory table in the combo box, sort Category Description in
ascending order.)
c. Select “Remember the value for later use” and click Next.
d. Provide a meaningful label for the combo box, e.g. “Step 2 - Search for Category:”.
e. Open the property sheet of the combo box and rename the combo box as
“ComboCategory”.
f. Add another combo box to search for Movie Title (choose Type I combo box, display
Movie Title from tblMovie table in the combo box, sort Movie Title in ascending order.)
g. Select “Store that value in this field” and choose “tblVideo_MovieNo”, and then click
Next (Don’t choose the MovieNo in tblMovie.)
h. Provide a meaningful label for the combo box, e.g. “Step 3 - Search for Movie:”.
l. On the “After Update” event of the 1st combo box (ComboCategory), click the “…”
button and then select Code Builder.
m. Type [ComboMovie].Requery between the Private Sub and End Sub statements.
You should notice that the Movie combo box is empty when you first open it.
After you pick a category in the Category combo box, then the Movie combo box will
show all movies belonging to the selected category. This shows that your code is
working. Does it work?
Question:
2. Why do we need to select “Remember the value for later use” in Step (c) on page 4 above?
Demonstration:
Compact the database when it is closed. Then Compress the compacted database.
Key Steps:
a. Close your database file.
b. Click the Database Tools and select
Compact and Repair Database.
c. Select the database file to compact.
d. Save the compacted database to a different
name.
Question:
4. What is the difference between “Compact” and “Compress”?
- end of document -