You need to use what you just learned and what you learned in the previous project, and maybe learn a little more. The exercises with databases will require more steps than in the other lessons!
Complete all parts of the following exercises. Don't forget to backup your Class disk when you have completed the exercises or whenever you stop for the day and saved a document along the way.
What you will do: | Rename the database Create relationships Create new tables Change field properties View subdatasheets Create a select query with criteria Create a parameter query Create calculated fields with text Use IIf Create an update query Create a Totals query with parameters Create a Crosstab query Use calculated fields with numbers Create a MakeTable query Create an Append query Delete a table Delete a relationship Repair a broken query ![]() Compact and repair the database Document the database |
Start with: Access open
This is a long exercise! You will use most of the skills you learned in the Tables and Queries project.
We have been using the Language Arts Classes database as an example when discussing new features. The original of this database was not formally "designed"; it just grew. So there are a number of things that could have been done better. (Yes, I say this even though I wrote it myself!) In this exercise you will use a start-up database based on the Language Arts Classes database. It has some tables with data. You will create some of the queries needed to calculate grades.
Some features of these tables are chosen to make it easier to work directly with the tables. That's not normally a good idea, but it can work well for the person who designed the tables! If we were going to work primarily with forms, we might choose differently.
You need a copy of one of the databases in your resource files. This database contains some of the tables from the original Language Arts Classes database but none of the queries, forms, or reports.
If you do not have a local copy of the resource files:
If you already have a local copy of the resource files:
Create relationships between the following tables:
Students - Scores, matching StudentID fields
Students - Six
Weeks Grades, matching StudentID fields.
Students - Bonus Points, matching StudentID fields
Scores - LetterGrades, matching LetterGrade fields
Scores - Assignments/Tests, matching A/T
ID fields
Scores - Classes/Subjects, matching C/S ID fields
Try to create relationships but don't do it:
Assignments/Tests and Graded Work Types on
the Type field.
Classes/Subjects and Students on the Class field.
Look carefully at the Edit
Relationship window for these two relationships. It shows that the relationship for both of these is "Indeterminate".
Whoops. That means that you can create a relationship BUT the values are not unique. Access cannot match
them with any certainty. Not a good idea!
(If you already created these two relationships, delete them now.)
You can fix these glitches, first by changing a table's design
and then by creating some new tables.
The field Type in the table Graded Work Types cannot be matched with the field Type in the table Assignments/Tests because the values are not required to be unique. You can fix that.
The combination of class and subject was useful but creates problems with relationships. You will create two new tables to help make things clearer to Access.
Save the layout and leave the Relationships window open until you finish the questions that follow.
Find the answers to the following questions by viewing the relationships or the various tables in datasheet or design view. Record your answers as your instructor directs.
After EACH change below, save the table. When you save, you might see a warning that some data may not fit the
new rules. Access hasn't looked yet! Let Access check the data.
(If you make several changes
and then find out that there is a problem, you won't know which change
caused the problem!)
If Access warns you that some data DOES violate the new validation rule or other settings, cancel the Save process and inspect the data. You will know that the problem was caused by your latest change to the table design. Make corrections to the data or table design, if necessary. For example, if a field is null that is now required to have a value, you should figure out what the appropriate value should be and enter it unless told otherwise in the directions. Then you will be able to make your change.
For this exercise you may need to temporarily delete a relationship in order to make some changes. But that can happen in other databases. In that case, you might need to close and reopen the Relationships or table design windows to make Access notice changes in relationships. Just be sure to re-create the relationship after you have corrected the problem.
Remember that text values must be enclosed with double quotes in a validation rule. Number values are NOT enclosed with quotes.
Set the table and field properties as described below.
Hint: Validation Rules must
be expressions, not sentences!
Subject:
Field Size = 1
Format: Formats as upper case
Validation Rule - requires the values R, S, or E
Validation Text = Choose R for Reading, S for
Spelling, or E for English
When you save the table, you get a warning
that data in Subject does not fit, but no hints as to which record(s)
are the problem. Look at the datasheet.
Assignment #65 does not have a value for Subject. Judging from the
description, the assignment was in English.
Do not correct this record now. You will make a correction later.
Type:
Field Size = 1
Format: Formats as upper case.
Validation Rule -requires using one of the values D, Q, T, B, or W
Validation Text = Choose D for Daily grade, Q for Quiz, T for Test, B for book report, W
for writing assignment
When you try to change the field size, Access refuses, saying that it is in a relationship. You must delete the relationship, change the field size, and recreate the relationship. You will probably have to close the Relationship and table windows to make Access realize that there is no longer a relationship.
Don't forget to recreate the relationship again.
Now that the tables are organized, you can start to work on queries that answer questions about the students and their grades, especially that most important question- "What's my grade?" That question is actually several questions since each student has scores for quizzes, daily assignments, and tests in three subjects. There are also averages for each of the six weeks grading period and for the year. Whew!
Do
not use the Save button on the Quick Access Toolbar to save a changed query. That will overwrite the original. Use Save Object As.
A 6-weeks grade is a weighted average of the average daily, quiz, and test grades for that subject. The daily grade may have bonus points added. So we have several calculations to do!
You will start with a fairly simple query and then add columns or other features as we go along. You will need a crosstab query to actually average the grades.
Run the query.
You should see a student's name in each row. There are 1552 records. We
lost 9 scores. Why?? Let's investigate.
The joins between tables are of the type that include records only when there are matching records. In other words, if one table has a record that has no matching records in the other table, it won't show in the query results. So, a student with no score for a particular assignment won't be listed for that assignment. Neither will scores that don't match a student. (Having a score without a student is a bad data entry error!)
Problem:
You had 143,612 records in the query results instead of 1552.
You did not create the join between the query and the Scores table. Access showed the cross-product of the query and the other
results (all possible combinations!). This query takes noticeably longer
to run.
Run the query again.
Ah ha! Those blank records have a StudentID of 1, which is not a normal ID number. If you check the Students table, you will find that there is no student with that ID number.
This glitch in data entering was my fault. A new student started class before I got her records, including her official ID number. I used 1 for her ID as a temporary number and changed the ID number later. I did not change her records in the Scores table to include her actual ID number. Big whoops! Those scores would not be counted when averaging her grades. (In real life I caught this error and calculated her grades correctly, of course!)
Problem:
StudentID does not show 1
You have used the StudentID field from the query QFullNames-withCalled instead of from
the table Scores. That query uses the StudentID field from the Students table. The value "1" appears only in
the Scores table, not in the Students table
Solution: In the query's design grid, in the Table row for the StudentID column, change the table to Scores.
Keyboard
shortcut to copy a value from the cell above in datasheet: CTRL + '
You can type in the value in the record at the top of the datasheet, use
the arrow key or Enter to move to the cell below. Hold CTRL and press
the apostrophe key. The value above is copied.
Problem:
Don't see a name in the FullName field after changing ID number
Make sure you put the correct number in and that you have exited the
cell.
We are finally done with this query!
Let's stop a minute and handle the problem of that student whose StudentID number was 1. You already changed the StudentID for the quiz scores but there may be other types of assignments and tests that also need an updated StudentID.
If we are sure that all scores with 1 for the StudentID belong to the same student, we can use an update query to fix the records.
Comment on database design: I did not think ahead! If the join between the tables Students and Scores allowed cascading updates, we would not have had this problem to start with. When I changed the student's ID number in the Students table, Access would have automatically updated all of the records in Scores and any other other table that had a join to Students that allowed cascading updates.
Now you can calculate the average of the quiz scores.
Set the values in the Total rows as follows:
Score - Avg
Ignore? - Where
The other columns can keep the default value of Group By.
Delete the column A/T ID.
Rearrange columns if necessary, to sort Ascending in the order Class, Subject, Grading Period, FullName. (They do not
have to be side-by-side, just in that order from left to right.)
QScores-Quiz-parameters after adding Totals row
Add parameters to Subject and GradingPeriod columns:
[Which subject - R or E?]
[Which grading period - 5 or 6?]
(The tables only have records for the last two 6-weeks grading
periods.)
Clearly you can manipulate the data in many ways with queries. You can add criteria and parameters to restrict the results. You can do sums and averages and counts using the Total row. You could also add formatting to make all of the averages have the same number of decimal places. We won't do that here.
The first step toward averaging grades is to get individual averages for each subject and grade type for each student. The query above did that just for quizzes.
Each student should have an average for 8 different SubjectType values, RD, RQ, RT, SD, ST, ED, EQ, ET for the grading period.
You found a data problem earlier but were not allowed to fix it. Now it is time!
Data entry error strikes again! This time I did not enter a subject for
the assignment and there was no validation rule to catch the error. How to fix this? First you must find which
assignment record is the bad one!
Inspect the query datasheet that you left open.
The datasheet may have updated automatically. No more plain D in the SubjectType column.
Note: You may have seen the screen flicker after you typed in the E and
exited the field. Access was updating the related Score records.
Note: If you typed a lower case e in the table, the Format property for that field turned it into an upper case E. BUT, the query shows what you typed! Surprised? I was! Go back to the table and enter an upper case E.
Problem:
Datasheet did not change
No changes? Not to worry!
Solution:
Press the F5 key to refresh the display.
Alternate method: Switch to Design View and run the query again.
Results: All rows have the correct SubjectType combo. Hurrah!
Crosstab queries are just what you need to calculate the averages wholesale instead of one type at a time or one subject at a time. It will take two queries to get what we really want. The first one is a crosstab query that calculates the daily, quiz, and test averages for each student for each subject. The second query will take those values and calculate the 6-weeks grade using formulas that give different weights to the parts.
Run the query.
Results: Each row is for one student and shows the averages for
each type and subject for the 6th grading period. Cool!
What are those ####?
Hash marks ####### show in a cell when the column is not wide enough to show the value. You can drag the right edge of the column heading to the right or double click it to make the column wide enough to show the widest item in the column that is showing.
Perhaps it is just me, but I really don't like seeing all of those
decimal places. It's not worth fixing here. We can wait until we get the
6-weeks grade, which is what goes on the report card, and then format the numbers.
The query you just created provides the numbers you need to do the 6-weeks grades. At last! You will create formulas to use those values in a new query.
Where does the 6-Weeks grade come from?
20% average of Daily scores, plus bonus points
30% average of Quiz scores
50% average of Tests
For Spelling there are no quizzes. The Daily and Test averages are each 50%.
Bonus points are recorded in a separate table. There is one value for each student for each of the 6-week terms.
Weighted formulas: You will need to replace the words below with the appropriate field name, operators, and grouping symbols. The parentheses are very, very, VERY important.
Reading or English average:
((2*(daily average+bonus points))+(3*quiz average)+(5*test average))/10Spelling average:
(daily average + test average)/2
Run the query.
Results: A row for each student shows the averages for each
subject-type (RD, RQ, RT, SD, ST, ED, EQ, ET), and for each
subject (RAvg, SAvg, EAvg) for the 6th 6-weeks term. Why just
the 6th term? Because the crosstab query QAverageScores won't let us use parameters.
To reduce the clutter, you need to change which columns show.
To change this query to do grades for a different grading period, you must
make two changes. The B field must be redefined for the grading period, like 5B for the 5th period, and the
criterion in the query QAverageScores must be changed to the grading period. Not a good plan.
Those bonus points in field B are a little bit of a problem. The points vary with each 6-weeks term. Because you set the criteria for the field B to 6B, the query can only do the calculation for the 6th 6-weeks.
The Bonus Points table has a separate column for each 6-weeks term for each student. Bad design! Better design would have each record include a student's ID, the number of the term, and the number of bonus points. You can move the data into such a table, with some careful planning. Action queries to the rescue!
First you will make a table with the records for the 5th grading period. Later you will append the records for the 6th grading period. Fixing bad table design is aggravating at best and requires careful planning.
Close the table.
Note: If you run the Make-Table query again and use the same name, you will lose the changes to the table's design.
You created a new field for the Bonus table which has records from the 5th term but the Term field is blank for all records. These records should show a Term value of 5. An update query can do that lickety-split (meaning very fast)!
Save the query as QUpdateBonus-5 and close it.
(Normally you would not want to keep this query but your instructor
will need to see that you have done what you were supposed to have done.)
Close the table.
You need to get the bonus points for the 6th 6-weeks added to the new table Bonus. An Append query is what you need this time.
Create a new query based on the Bonus Points table.
Drag the fields StudentID and 6B to the grid.
Change the query to an Append query.
In the dialog that appears, select the table Bonus as the one to which you want to append records.
Click on OK.
In the Append to: row that appears, select for the column 6B the field Points.
Run the query.
Whoops. You get an error message.
Choose No.
You don't want to append the records just yet. There is a primary key
violation. Double-whoops.
When we designed the Bonus table, we set StudentID as the primary key. But now you are appending another set of points for each student. Primary keys must be unique! You must revise the table design.
Add a new field BonusID and make it
an AutoNumber field and the primary key.
Save and close the table.
Run the append query again.
This time you get the message that you are
about to append 92 records. Yes!
Save the query are QAppendBonus-for6thTerm.
Close the query.
Open the table Bonus and scroll through the records.
The values for Term for the rows you just
added are all blank. You
have another step to do.
Leave the table open this time.
Point of Confusion: Updates will work even if the table is open. But, append queries won't work when the table is open.
Open the query QUpdateBonus-5 in Design View.
(Be careful to open action queries in Design View unless you really
mean to perform the action now!)
In the Update to: row, type 6.
In the Criteria row, type is null.
View the datasheet before you run the query!
You should
see 92 rows only, all with Term field blank.
Run the update query.
Close the query without saving changes.
Correct Data Error: That StudentID of 1 is still hanging around! Fortunately that
student earned no bonus points. Change the 1 to 40102 in
the two records in the table now.
You don't need the table Bonus Points anymore. All its data is now in the Bonus table. But, before deleting an object in Access, you should be sure that you won't be breaking something else! A query, form, or report might use your object. Access shows such dependencies in a task pane. For earlier versions of Access you had to have a good memory or do some inspecting.
Select the table Bonus Points in the Navigation Pane.
From the Database Tools ribbon tab, click on Object Dependencies .
Note: You may see a message about updating dependency information.
Choose OK. It won't really take very long in this case.
The task pane opens and shows a tree of
dependencies. What depends on this table?
Table Students,
Q6WeeksGrades-6th, QAppendBonusofr6thTerm,
and QMakeTable-Bonus.
Thinking: What problems will it cause to delete the table Bonus Points?
Delete the table Bonus Points.
A message box opens. Access won't let you delete without warnings! There is a relationship between this table and another. You
must delete the relationship first.
Click on OK .
A second message box appears and offers to remove the relationship for
you. (You have to read it carefully to see what it actually says!)
Click on OK in the second message box, too.
The table is deleted.
Open the Relationships window.
Add the table Bonus to the Relationships window.
If necessary, create a join between Students and Bonus using the StudentID field.
Close the Relationships window and save the changes to the layout.
Now that you have straightened out the bonus points and have deleted the Bonus Points table, you must fix the query that used that table. It should use fields from the Bonus table instead. You must make sure that the expressions to calculate grades can find the bonus point values. This is where it gets tricky if you do not pay very close attention!
Click on OK.
The query opens in SQL view instead of Design View.
Not a pleasant sight! Unlike earlier versions, Access 2007, 2010, 2013, and 2016 will not open the Design View when there are such substantial errors. You can, however, edit the expression... very carefully.
Problem:
The query failed to open.
If you try to run this query by double-clicking it or using the Open
button, you get an error message. The query won't run at all since the
Bonus Points table does not exist anymore.
Edit the SQL expression: to change [Bonus Points].[6B] AS B to [Bonus].[Points] AS B
(The 'B' is used in the formulas to calculate averages for the bonus points. It makes the formula a bit easier to read in Design View.)
If the text is too small for you to read easily, copy the whole expression and paste into a text editor. You can enlarge the font and do all of the editing. Then copy the edited version. Switch back to Access and select the SQL expression. Paste. Be very, very sure that you get ALL of the expression each time you copy!!!
Run the query.
Results: Sorted by Class, FullName, and Term. So each student has a row for term 5
and one for term 6.
Yes, there are some really bad grades in this table!
Now you can attack those ugly decimals. The Round function helps you manage the number of decimal places showing. The values are rounded, not just cut off.
General form:
Round(expression, number of decimal places to show)
If no number is entered, the Round function will produce
only integers.
Examples:
Round([Average],2) would display 19.23649 as 19.24, rounding
up to show 2 decimal places.
Round ([Price]*1.0925) would display 19.23649 as 19,
rounding down to show 0 decimal places.
Run the query.
The datasheet now shows rounded values. Much easier to read.
Problem: Averages are in integers with no decimal part.
Why: You omitted the comma and the 1.
Solution: Edit the formula.
You have done a LOT of work. The file is almost certainly fragmented on your Class disk.
There are far too many tables and queries to document all of them! Some were saved just so you could show your instructor that you did the work. You will print just enough of what you've done to show that you know how to print and use the documentation.
Relationships:
Print the Relationships report from the Relationships window in
Landscape orientation.
The file name in the report header includes your own name.
(Access will not remember the orientation. You must change the defaults
every time.)
Table
Datasheet:
Open the Print Preview for the table Students.
Whoops. A whole row does not quite fit in the width available. A second
page prints to get the rest of the Notes field, even though no text was
actually cut off. Overkill!
Change the margins in the Page Setup to half an inch left and right.
If necessary, resize columns so that all values are readable and the row fits across one sheet.
Access will not let you adjust the header and footer for these reports.
Print the datasheet of the table Students.
(2 or 3
pages)
Write your name and "Ex. 3-2" at the top left of each page
Documenter report: Table
Create the Documenter report for the Students table. (6 or 7 pages)
Print.
Write your name and "Ex. 3-2" at the top left of each page.
Highlight or circle the answers to the following questions on the report:
Documenter report: Query
Select the query QAverageScores in the Documenter dialog.
Click the Options buttons and change the Options so that the document will not include any of the permissions or index information.
Access will remember
your Options choices for the next time your print a Documenter report.
Create and print the report. (4 or 5 pages)
Write your name and "Ex. 3-2" at the top left of each page.
Highlight or circle the answers to the following questions on the report:
Object
Dependencies:
Show the Object Dependencies task pane for the query Q6WeeksGrades -
Objects that I depend on.
(Access 2007 leaves out the table Classes.)
Capture a screen shot of the window and paste it into Microsoft Paint, or similar graphics program.
Crop the image to show just the task pane.
Write your name and "Ex. 3-2" at the top left of the page with the Text tool.
Print the screen shot.
Save to your Class disk in the folder databases project3 as ex3-2-dependencies.png in PNG format.
This exercise uses a file from the databases resource files.
You cannot make changes to these files and save them in the same place. Save the changed documents to your Class disk. This keeps the original resource files intact in case you need to start over or another student will be using this same computer.
How to handle a full disk