Essential Access Exercises
Essential Access Exercises
Essential Access
Exercises
IT
www.york.ac.uk/it-services/training
Essential Access Tasks
Exercises to accompany Essential Access Course
Books 1 & 2
Sample files for use with these exercises can be found on the shared Teaching (T:) drive,
accessible from any classroom PC and other centrally managed computers. The folder needed is:
Teaching (T:)\IT Training\Essential Access
Users cannot save to this drive, so you will need to copy the entire Essential Access folder to your
own documents location.
The sample file to be used is indicated at the start of each set of exercises.
Version: May 2019
1 ~ Understanding Databases
Open the Access database Student Records 1.accdb for these exercises
Open the Students table in datasheet view and enter the following new student either by
navigating to the empty field or using the 'New record' button. Note the pencil symbol when
editing:
studentID forename surname email
10510 Paul Hitch [email protected]
Enter yourself as a new student. Save by moving to a different record or using the Save
button.
If you left the studentID field empty you will receive a warning message. This is because
studentID is the primary key and must be included in any record.
Either enter a made-up studentID (10505) or delete the record.
Find student number 10330, Tara Maples. Correct her email to yahoo.com.
Close Students and open the Modules table. Find the Plasma Physics module (moduleID
PHY201) and set the roomID to G/A/114.
Extension
Prof Leo Richards is the new tutor for the module CSC203, AJAX Development. Locate his
TutorID (Tutors table) and update the tutorID for this module in the Modules table.
Joseph Smith has received a mark of 79 in Nuclear Chemistry. Enter this into the
ModuleChoices table.
2 ~ Query Essentials
Continue using the Access database Student Records 1.accdb for these exercises
1 Create a new query in Design view. Add the Students table. You may want to resize the table
so you can see all the fields listed.
Add studentID, forename and surname to the grid.
(Try using both the double-click and drag-and-drop methods and see which you prefer)
Use the View button to switch to Datasheet view. Find student 10091 and correct her name
to Suzy Watson.
Note: Even though queries do not store data, the results of a query are from the underlying
table, and a change made here is changing the data stored within the table.)
Switch back to Design view. Apply a Sort to order surnames alphabetically and check the
results in the datasheet view.
Extension
Create a new query that will display the studentID, name and date of birth for all students
born on 26/09/1995. (1)
Modify the query to find students born in 1995 (ie between 01/01/1995 and 31/12/1995).
(57)
Hint: See Conditions, ranges and wildcards on p 10
Modify the query again to only show 1st years born in 1995. Also include their email address
and sort by surname. (24)
Save the query as qryDob
Create a query to show all 2nd and 3rd year students. (330)
Save the query as qrySecondAndThirdYears
2
Essential Access: Exercises
1 We want to view information about the modules the students are taking. This will require
data from two related tables, Students and ModuleChoices. Both tables contain studentID
fields which are linked with a 1-to-many relationship.
Create a new query and add only the Students table. Add studentID and both name fields;
view the datasheet. (502 records)
Add the table ModuleChoices and view the datasheet again.
There are about 3 times as many results as before. This is because each student studies
several modules and is listed once for each module they take.
Add the moduleID field and view the datasheet again to see the different modules each
student is taking.
Return to the design and filter the results to show details for studentID 10175. (David
McDonald). (3)
It would be helpful to see the module titles, and you may also need to view other module
information. To do this we need to add a third table to our query.
Add the Modules table to the design and include the moduleName and credits fields.
View the datasheet again.
Clear the studentID from the criteria and save the query as qryModules.
Extension
Create a new query that will list each module and the tutor who teaches it. Show the module
ID, module name and term along with the Tutor’s ID, full name and email. (44)
Modify the design to display only History modules.
Hint: Use wildcards to find only the modules with IDs which start with HIS. (6)
Modify the query to show all modules again. Add the room ID and capacity. You will need to
add a 3rd table to do this. (40)
Why do you think adding the rooms table to the query has reduced the number of records
returned? Looking carefully at the Modules table may help.
Modify your query to show the college that the rooms are in.
Save the query with a suitable name.
3
3 ~ Editing Table Design
Open the Access database Student Records 2.accdb for these exercises.
1 Open the Modules table in design view. Examine the fields in this table, paying attention to
the data type of each, and the different field properties available.
Set the field size of moduleID to prevent codes longer than 6 characters from being entered.
The departmentID is always a 3 character code. Change the field size, and format it to always
display in uppercase.
Some modules are compulsory for all students. Add a new field called compulsory with
Yes/No data type to record this. Set the default value to Yes.
There are never more than 100 credits awarded for a module. Adjust the number field size to
the most appropriate type. Set a validation rule to prevent entries higher than 100 and enter
suitable validation text.
Save your changes to the table design and switch to datasheet view. Pay attention to the
warning messages. Enter an imaginary new module. Try entering:
A new table
Create a new table in design view called Tutors. Add the following fields:
Switch to datasheet view and enter a new tutor. Note tutorID is automatically completed
when you start entering data in any other fields.
4
Essential Access: Exercises
3.1 - Relationships
Use the Access database Student Records 3.accdb for these exercises.
1 Open the Relationships window from the Database Tools tab. This isn’t currently showing all
tables in the database. Add the Departments and Tutors tables.
Create a relationship between tutorID (Tutors table) and tutorID (Modules table) and
enforce referential integrity.
Open the Departments table and attempt to change POL to PEP again. You should receive no
errors. Open the Modules table. Politics modules will now show this new PEP department
code.
(Note: This is due to the ‘Cascade updates’ option)
Return to the Departments table and delete the Politics department. You will receive a
warning that because of the cascade delete this will not only delete Politics from the
departments table but also delete all related records in other tables. Choose Yes and return
to the modules table to confirm that all Politics modules have now gone.
(Note: cascade delete should be used very carefully)
5
3.2 - Importing data
Use the Access database Student Records 2.accdb for these exercises.
1 The Departments.xlsx Excel file in the Essential Access folder contains department
information. Import this file into a new table. A unique 3 character department code is
included in this spreadsheet. Select this as the primary key rather than letting Access add its
own. Name this new table Departments.
Open the newly imported Departments table in design view. The field names all contain
spaces which are normally best avoided. Rename the fields:
a) Department Code -> deptID
b) Department Name -> deptName
c) Head of Department -> headOfDept
Set the field size of deptID to prevent new entries being longer than 3 characters.
Close and save the changes to Departments.
Extension
The RoomsAndColleges.accdb Access file in the Essential Access folder contains a table of
room information and a table of college information. Import both these tables.
It is possible to import other Access database objects, such as Forms, Reports and Queries.
Import qryLargeRooms from RoomsAndColleges.accdb
Modify qryLargeRooms to show only the large rooms on the East campus. (10)
NewStudents.txt contains a list of students. Append these to the Students table. Check the
Students table to see how the data looks. Open the text file to see why the data has not
imported correctly.
6
Essential Access: Exercises
4 ~ Creative Queries
4.1 - Calculated fields in Queries
Open the Access database Student Records 4.accdb.
Note: You will need to enable active content for some of the exercises.
We want a list of some students showing their module result and their name displayed sensibly.
1 Create a new query using Students, ModuleChoices and Modules. Include the fields:
studentID, forename, surname, modName, mark (1502)
Add the necessary extra fields and criteria to show only modules from the History
department (departmentID: HIS) running in the first term (56).
Save the query as qryResultsList.
The mark is out of 120. Add a calculated field called adjustedMark to show the mark as a
percentage. Set this to display 1 decimal place.
(Tip: divide the mark by 120 and then use the field properties to set the format of the
Adjusted Mark field to be Percent.)
Modify the query design so the records are listed in descending order by adjusted mark
(range is 80.8% to 23.3%).
Add a new field, fullName and use concatenation to join the students’ forename and
surname together in this field, ensuring a space is included. Position the field to display as
the first column on the left.
Save the query.
Extension
Add sorting to the query design to display the results ordered first by surname, then by
forename and hide the forename and surname fields from the result.
Modify the fullName calculated field so names are displayed in the format Surname, Initial
(eg Smith, J)
1 Create a new query to show the module name (Modules) and mark (ModuleChoices). Enable
the Totals row, and configure to calculate the average of the marks (to 2 decimal places).
Save query as qryAverageMarks.
Modify the query to show average marks by department rather than module. You will need
to add another table in order to include the department name.
In place of averaged mark field, configure a calculated field that averages the adjusted mark
as a percentage (marks are out of 120), shown to 1 decimal place. (Biology 50.3%)
7
4.3 - Parameter queries
Continue using the Access database Student Records 4.accdb.
The discrepancy arises because modules that have no room allocated are not included.
Modify the join between Modules and Rooms to be an outer join showing all records from
Modules. Run the query again and note that all modules (44) are now included, with gaps
where no room has been allocated.
Modify the outer join to show all records from Rooms. Note the number of records (116).
Open the Rooms table and note the total number of rooms (100).
Why are these numbers different? (sorting the query by roomID may help.)
We don’t need currentYear in our alumni table; modify the query so this field is not included
in the display, but is still used in the filter.
8
Essential Access: Exercises
View the datasheet and check the results look OK. (151)
It won’t work, but run the query to see the error message. You are unable to delete these
students because there are still entries for them in ModuleChoices. Removing the students
would break referential integrity.
Save the query as qryDelete3rdYears and close it.
Select Database Tools > Relationships and modify the relationship between Students and
ModuleChoices to cascade delete. Close the relationships window, saving changes.
Run qryDelete3rdYears again and then view the Students table to confirm all 3rd Years are
deleted. (349)
Promotion
Create a new query that selects all 2nd years (179). Change this to an Update query to
change all 2nd years to 3rd years. Run the query and look in Students to confirm it worked.
Why must you promote 2nd years before 1st years?
Modify the query so it changes all 1st years to 2nd years and run it again. (170)
Save the query as qryUpdateYears and close it.
For the future…
Create and run an Append query to add all current 3rd years to the Alumni table. You can
only include fields that exist in the Alumni table. (Tip: save a copy of qryMakeAlumniTable
and change this to an Append query).
9
5 ~ Data Design: Rent-A-Toy
Rent-A-Toy is a service run by a local community centre. They own a collection of toys which local
residents may borrow. New toys are purchased regularly and old ones reaching end of life are
decommissioned. The loans are to be managed using an Access database system.
Parents must register, providing contact details including address, phone and email (if
they have one) and must be aged over 18
Each toy has a suggested age range to help parents choose
Toys are borrowed initially for 2 weeks, which can be extended by a further 2 weeks only
once
Toys are purchased with council funds, so statistics on the service need to be generated
once a month, including details of the costs of new purchases
When a toy is taken out of use the reason must be recorded so its value can be written
off
Task:
1 Write down the data items you think will need to be recorded in order to create this system.
Group these items according to subject and use this to create a diagram of the data
structure, showing primary keys, foreign keys and relationships.
Use the space on the next page for your design.
10
Essential Access: Exercises
11
6 ~ Reports
Open the Access database Students Records 5.accdb.
Note: You will need to enable active content for some of the exercises.
1 Create a new query on which to base the report. This needs to include:
Return to design view and tidy the report, adjusting label and field size/positions.
Note: When viewing a Print Preview, use the Close Print Preview button to return to design
view.
Extension:
Add a field to the report footer to count the total number of modules listed. Use the Count()
function in an unbound text box. (44)
Reopen and modify the query to list only modules from the Politics department (deptID
POL). (9)
After saving and closing the query, view the report again and note the change in the number
of modules.
Replace the tutor title, forename and surname fields with a single field joining these
together.
12
Essential Access: Exercises
We want to create a report that lists the full names of all first year students, their student ID and
the modules they are taking with the mark they received.
1 Create a new query including the tables and fields you think will be needed.
Include a filter in the query to only show students currently in year 1. (512)
Note how this query shows each student multiple times.
Close and save the query as qryStudentModules.
Create a grouped report based on this query. Group the report by studentID and sort by
modName.
Tidy the report, adjusting label and field size/positions. Depending on how you chose the
report grouping you may have some student information in the detail section. If so, move it
to the group header.
Extension:
Modify the report to include each student’s average mark (in an unbound control). You will
need to ensure that the footer section for each student is displayed first. This is done
through opening the Group & Sort window. Modify the properties of this average to display
to one decimal place.
Hint: See Group & Total configuration on p 14
Add a field in the report footer to show the total number of students. You may need to drag
the report footer out from the Design view.
Modify the underlying query to only show modules from the Chemistry department (deptID
CHE). View report to see how it has changed.
13
7 ~ Forms
Continue using the Access database Student Records 5.accdb for these exercises.
2 View the form and use the record selectors to move through the records. Enter a new tutor
using the New Record button.
3 Create a second form based on the Tutors table, but this time choose a Tabular layout. Name
this form frmTutors2. Compare this form to frmTutors1.
4 Modify the design of the tabular form to remove the wasted vertical space in some of the
fields.
3 Modify qryStudents to only show 1st years. Open frmStudents. Note that the same form
now only shows 1st years. (170)
7.3 - Subforms
1 Create a new query showing studentID and mark from the ModuleChoices table and
modName, credits and deptID from the Modules table. Save this as qryStudentMarks.
2 Use the Form Wizard to create a form using all fields from this query. Choose to view your
data by ModuleChoices and select the Tabular layout. Save the form as frmStudentMarks.
This form is not very useful as it is, but when used as a subform with the frmStudents created
earlier it will be very effective.
14
Essential Access: Exercises
Modify frmStudents to include the average of each student’s marks. Use a Text box in the
footer of the subform to do this. Set this to display one decimal place.
Tidy up the form by removing the record selectors, navigation buttons and scroll bars on the
subform and adding more useful title bars.
Sort by deptname.
Choose to ‘Hide key column’.
Store the value in deptID.
Give it a suitable name
3 Cycle through the records. Note the combo box and the deptid fields display corresponding
values. Selecting a department name from the combo box changes the value stored in the
deptid field.
May 2019
15