Microsoft Access Worksheet
Microsoft Access Worksheet
Microsoft Access Worksheet
Designer View
Datasheet View
MS Access Tutorial
Page 1
Demonstration:
Switch between the Datasheet view and the Design view of the Customer table.
Key Steps:
(a) Open the Customer table (tblCustomer).
(b) Click the Home tab and click View in the Views group to toggle between the current view and the previous
view.
(c) Use the Navigation bar (on the bottom of each table) to go to Next Record, and then Last Record.
(d) Use the Search box to locate a customer, e.g. Susan. What do you see?
(e) Add a new customer record using any name. Click the record selector
to save the record. Are
there any other ways to save the record?
Understanding Relationships
Microsoft Access has the ability to create relationship between two tables, whereas Excel cannot.
When relational databases are designed properly, users can easily combine data from multiple tables to create
queries, forms and reports.
Relationships are created in the Relationships window after the database tables are created.
The most common method of connecting two tables is to connect the primary key from one table to the foreign
key of another. For example, the MovieNo (primary key) in the Movie table is joined to the MovieNo (foreign
key) in the Video table.
primary
key
foreign
key
MS Access Tutorial
Page 2
Remember, a primary key is a field that uniquely identifies each record in a table.
A foreign key is a field in a table (Child table) and it is also the primary key of another table (Parent table).
Question: Refer to the diagram above, which one is the Parent table and which one is the Child table?
tblMovie is the _________________ table and tblVideo is the ________________ table.
Demonstration:
Test the Referential Integrity.
Key Steps:
(a) Click Database Tools tab and click Relationships
window opens.
Can you explain the relationships among these four tables shown in the diagram above?
(b) Delete a customer record from the tblCustomer table when the customer has made a reservation for a video,
i.e. the MemberNo exists in one of the reservation records in the tblReservation table. (You should open the
tblReservation table and pick a customer first.)
What is the error message? _________________________________________________________
MS Access Tutorial
Page 3
Selected fields
that will be
displayed in the
query result,
i.e. dataset.
Specify sorting
sequence.
By default, the
records are listed
in primary key
sequence.
Specify the
selection criteria.
The Query Design view consists of two parts. The top portion contains tables with their respective field names.
If a query contains more than one table, the join lines between tables will be displayed as they are created in the
Relationships window.
The bottom portion (known as the Query Design Grid) contains columns and rows. Each field in the query has
its own column and contains multiple rows. The rows permit you to control the query results.
The Field row displays the field name.
The Table row displays the data source.
The Sort row enables you to sort in ascending or descending order.
The Show row controls whether the field will be displayed in the query results.
The Criteria row is used to set the rules that determine which records will be selected, e.g. a list of
movies with video in DVD format.
The results of the query are shown in Datasheet view.
Demonstration
1) Create a query using Query Wizard to list all the movies in the database, sorted by title. (qryMovie)
Key Steps:
(a) Click the Create tab and click Query Wizard
MS Access Tutorial
Page 4
Key Steps:
(c) Select tblMovie table in the Query Wizard dialog box.
(d) Select the fields and add them to the Selected Fields list box using the directional arrows.
(e) Choose the Detail query to show every field of every record in the result.
(f) Enter the name of the query, qryMovie.
Question: How can we create this query without using Query Wizard? _______________________
COMM 205 Winter 2015 Term 2
Copyright 2016 Y.M.Cheung
MS Access Tutorial
Page 5
Demonstration:
2) Create a query to list the title, length, and synopsis of all movies with the Rating equal to PG. Sort the
result by Title. (qryMovieRating)
3) Create a query to list the title, length, and synopsis of all movies that are categorized as A or B.
(qryMovieCatAB)
4) Create a query to list the title, length, and synopsis of all movies that have DVD format. Sort the result by
Title. Do not display the format field. (qryVideoDVD)
MS Access Tutorial
Page 6
Column Headings
Summary Field
Demonstration:
7) Create a crosstab query to show the total rental charges by movie category and video format.
(qryMovieRental_Crosstab)
Key Steps:
(a) Create a query using Query Wizard and select
the Crosstab Query Wizard.
Row Headings
To save time, you may use the query qryMovieRental_demo if you havent created the query qryMovieRental.
MS Access Tutorial
Page 7
Key Steps:
(f) Select Format field from the fields list, add it
to the Column Headings.
Format
Column Headings
(h) Select Charge field from the fields list and then
select Sum from the Functions list.
(i) Click Next.
Charge
Sum
(l) Open the query in Design View. Compare this with the Query Result shown on page 7.
MS Access Tutorial
Page 8
Practice:
(You may create the following queries after class and you dont need to submit your answers. Suggested
solutions will be discussed in class next week.)
1) Create a simple query to list the movie title, category code, and synopsis of all movies of which length is
greater than 120 minutes and rating is PG. Sort the result by title. (qryMoviePG)
Write down the criteria:__________________________________________________________
2) Create a simple query to list the movie title, length, synopsis, and format of those videos that have at least 3
copies. (qryVideo3Copies)
Write down the criteria:__________________________________________________________
3) Create a simple query to list the video rentals that are two weeks overdue. The list should include the
customer name (last name and first name), customers phone number, movie title, video format, the date the
video is rented out and the due date. (qryRentalOverdue)
(Hint: Use the function Date( ) to retrieve todays date, i.e. system date.)
Write down the criteria:__________________________________________________________
4) Create a crosstab query to show the average rental duration (in days) by movie title and video format.
(qryAverageDuration_Crosstab)
(Hint: Create this query using query qryMovieRental.)
Row Heading(s): ___________________________________________________
Column Heading(s): ________________________________________________
Function: _________________________________________________________
5) Create a crosstab query to show the number of customers by city and customer type.
(qryCustType_Crosstab)
Row Heading(s): ___________________________________________________
Column Heading(s): ________________________________________________
Function: _________________________________________________________
- End of document COMM 205 Winter 2015 Term 2
Copyright 2016 Y.M.Cheung
MS Access Tutorial
Page 9