Notes 3 - Work With Tables and Database Records
Notes 3 - Work With Tables and Database Records
Database Records 3
LESSON SKILL MATRIX
Skill Exam Objective Objective Number
KEY TERMS
• ascending
• composite key
• descending
• filter
• foreign key
• innermost field
• outermost field
• referential integrity
• sort
• wildcard
49
50 Lesson 3
Fourth Coffee is a national chain of coffee shops. A new store recently opened in
your neighborhood. You were able to get a part-time job working in the office,
helping the office manager organize data on the computer. In addition to being
a traditional neighborhood coffee shop, the store has also started selling cof-
fees to companies for use at their business sites. It is your job to manage the
inventory, customers, and order tables in Access. In this lesson, you learn to
navigate among records; enter, edit, and delete records; find and replace data;
sort and filter data; attach and detach documents; and define, modify, and print
table relationships.
GET READY. Before you begin these steps, be sure to turn on and/or log on to your
computer and start Access.
1. OPEN Fourth Coffee from the data files for this lesson.
The Fourth Coffee 2. Click the File tab, then click the Save Database As command. The Save As dialog box
file for this lesson is appears. Key Fourth Coffee XXX (where XXX is your initials) in the File name box.
available on the book Find the location where you will save the solution files for this lesson and click Save.
companion website or in 3. In the Navigation Pane, double-click Coffee Inventory: Table to open the table.
WileyPLUS.
4. Notice that the first cell of the first record is selected.
5. Press the Down Arrow key to move down to the next row. Notice that the cell
is selected.
6. Press the Right Arrow key to move to the Product Name field.
WileyPLUS Extra! features an
online tutorial of this task. 7. Press the Tab key to move to the next cell.
8. Press the Tab key to move to the next cell.
9. Press the Tab key to move to the next row.
10. Press Ctrl+Down Arrow to move to the first field of the last record.
PAUSE. LEAVE the database open to use in the next exercise.
Table 3-1 lists keys and key combinations for moving among records.
Work with Tables and Database Records 51
Table 3-1
Commands Results
Keyboard Commands for
Navigating Records Tab or Right Arrow Moves cursor to the next field
End Moves cursor to the last field in the current record
ShiftTab or Left Arrow Moves cursor to the previous field
Home Moves cursor to the first field in the current record
Down Arrow Moves cursor to the current field in the next record
CtrlDown Arrow Moves cursor to the current field in the last record
CtrlEnd Moves cursor to the last field in the last record
Up Arrow Moves cursor to the current field in the previous record
CtrlUp Arrow Moves cursor to the current field in the first record
CtrlHome Moves cursor to the first field in the first record
Figure 3-1
Record navigation buttons
Last record
Previous
record Filter indicator
Search box
First record Add new (blank) record
Current record Next record
52 Lesson 3
2. Click the Next record button. The selection moves to the next record.
3. Select and then delete the number 2 in the Current Record box. Key 5 and press Enter.
The selection moves to the fifth record.
4. Click the Search box to position the insertion point. Key sunrise into the Search box.
Notice that the selection moves to the first occurrence of the word Sunrise.
5. Press Enter. The selection moves to the next occurrence of the word Sunrise.
6. Click the New (blank) record button. The insertion point moves to the first column and
last row of the table.
PAUSE. LEAVE the database open to use in the next exercise.
SOFTWARE ORIENTATION
Record Records
Shortcut menu group
Record
Selector
box
Figure 3-2
Records group, Record Selector
box, and Record Shortcut menu
Use the commands in the Records group and the Record Shortcut menu, as well as the
Record Selector box (a blank square to the left of a record), to assist you in entering record
data and inserting and deleting records.
Work with Tables and Database Records 53
Figure 3-3
Blank record in
Datasheet View
2. Key 21905 and press Tab. Notice that the asterisk has changed to a pencil icon, as
shown in Figure 3-4, indicating that the record is being edited.
Figure 3-4
Entering data into a record Indicates that
the record is
being edited
Another Way
An easy way to
select an entire record is to
click the Record Selector box.
If you need to select other
records above or below it,
you can drag the mouse up
or down to include those in 12. A dialog box appears, as shown in Figure 3-6, asking if you are sure you want to
the selection. To delete one or delete the record. Click Yes.
more selected records, right-
click the Select All button and
choose Delete Record from the
shortcut menu.
Figure 3-6
Confirm deletion dialog box
Another Way
To delete a record
without selecting it, place the
cursor in one of the fields of
a record and click the Delete 13. Notice that the Undo button on the Quick Access Toolbar is not available because you
menu on the Home tab in the cannot undo a deletion. Close the table.
Records group. Select Delete
Record from the menu. PAUSE. LEAVE the database open to use in the next exercise.
As you become more advanced in your knowledge of Access, you may want to create a delete
Ref query that can delete multiple records at once. You learn more about queries in Lesson 8.
Work with Tables and Database Records 55
Figure 3-7
Primary Key
Primary Key
button
2.4.1
How do you designate a
primary key in an Access table? PAUSE. LEAVE the table open to use in the next exercise.
56 Lesson 3
Figure 3-8
Primary Key row and another
row selected
3. On the Design tab, in the Tools group, click the Primary Key button. A key icon should
be displayed beside both of the two selected fields.
4. With the rows still selected, click the Primary Key button again to remove the primary
key designation from both fields.
5. Click on any field name to remove the selection.
6. Click the Row Selector box beside the Order ID row. Press and hold the Ctrl key and
click the Row Selector box beside the Customer ID row. Both fields should be selected.
7. On the Design tab, in the Tools group, click the Primary Key button. Both rows should
have a key displayed beside them.
8. Click the Save button on the Quick Access Toolbar.
9. Close the Design View.
PAUSE. LEAVE the database open to use in the next exercise.
In the Find and Replace dialog box, key the text or numbers that you want to search for into
the Find What box and click Find Next to locate the record containing the data. If you want to
replace the data, key the new data into the Replace With box and click Replace or Replace All.
Take Note When replacing data, it is usually a good practice to click Replace instead of Replace All so that
you can confirm each replacement to make sure that it is correct.
Figure 3-9
Find and Replace dialog box
58 Lesson 3
8. Click the Find Next button. Access searches the table and finds and selects the
word Elm.
2.3.1
9. Click the Replace button. Access replaces Elm with Little Elm.
How do you find data 10. Click the Find Next button. Access finds Elm in the new text that was just inserted.
within a table? 11. Click Find Next again. Access displays a message saying that no more occurrences of
the word have been found. Click OK.
12. Click Cancel to close the Find and Replace dialog box.
Another Way
To open the Find 13. Press the down arrow to remove the selection and allow Access to save the change.
tab in the Find and Replace 14. Close the table.
dialog box using the keyboard, PAUSE. LEAVE the database open to use in the next exercise.
press Ctrl+F. To open the
Replace tab, press Ctrl+H.
Take Note If you want to use the Find and Replace dialog box to search for characters that are used as
wildcards, such as a question mark, you must enclose that character in brackets, for example [?].
Follow this rule when searching for all wildcard characters except exclamation points (!) and
closing brackets (]).
Take Note You cannot attach files to databases created in versions of Access prior to Access 2007. You
cannot share attachments with a database created in these prior versions of Access.
Take Note You can attach a maximum total of 2 gigabytes of data, but each individual file cannot exceed
256 megabytes in size.
Another Way If the program that was used to create the attached file is installed on your computer, you can
You can also right- open and edit the file using that program. For example, if you open a Word resume that is
click in the Attachments field to attached to a record, the Word program starts and you view the document in Word. If you do
display a shortcut menu. Select not have the program that was used to create a file, Access prompts you to choose a program you
Manage Attachments from do have to view the file.
the menu to display the
Attachments dialog box.
Work with Tables and Database Records 59
Figure 3-10
More Fields menu
5. Double-click the first row of the Attachments field. The Attachments dialog
The invoice 100 file box appears.
for this lesson is available 6. Click the Add button. Navigate to the data files for this lesson and select Invoice100.docx.
on the book companion Click Open. The document appears in the Attachments dialog box, as shown in
website or in WileyPLUS. Figure 3-11.
Figure 3-11
Attachments dialog box
7. Click OK. The number of attachments in the first record changes to 1, as shown in
Figure 3-12.
Number of
attachments
60 Lesson 3
8. Double-click the attachment number in the Attachment field. The Attachments dialog
box appears.
9. Click the Open button. The attachment, an invoice document, opens in Microsoft Word.
10. Click the Close button to close the invoice document.
11. Click the Access button on the taskbar, if necessary, to return to Access.
12. In the Attachments dialog box, click the Remove button, and click OK. The attachment
is removed from the record.
13. Close the Order Summary table.
PAUSE. LEAVE the database open to use in the next exercise.
Take Note Once a field has been set to the Attachment data type, it cannot be converted to another
data type.
SOFTWARE ORIENTATION
Advanced menu
To sort text, numbers, dates, or other data types in a column, you first need to select the column.
Then click the Ascending or Descending button in the Sort & Filter group of the Home tab.
You can also right-click a selected column and choose a Sort command from the shortcut menu.
The available sort commands in the shortcut menu vary depending on the type of data in the
column, as shown in Table 3-2.
Table 3-2
Type of Data Sort Command on the Shortcut Menu
Sort Commands on the
Shortcut Menu
Number, Currency, or AutoNumber
Yes/No
Date/Time
You can also sort records on multiple fields. When you are using multiple fields, determine which
order you want them to be sorted in. The primary sort field is called the outermost field. A
secondary sort field is called an innermost field. For example, if you want to sort a contact
list so that each employee’s last name is sorted primarily and first name is sorted secondarily, Last
Name would be the outermost field and First Name would be the innermost field. In your com-
pleted sort, Wright, David, would be listed before Wright, Steven, in an A to Z (ascending) sort.
When designating the sort order, however, you select the innermost field first and choose the type
of sort you want from the shortcut menu. Then select the outermost field and select the type of
sort that you want.
After you sort one or more columns, Access inserts sort arrows in the header row to show that
the field is sorted. These sort commands remain with the table until you remove them. When
you want to remove a sort order, click the Remove Sort button from the Sort & Filter group on
the Home tab. This removes the sorting commands from all the fields in the table. In a table
with more than one sorted field, you cannot remove just one sort.
Figure 3-14
Shortcut menu
62 Lesson 3
4. The data is sorted and an arrow is inserted in the header row, as shown in Figure 3-15,
indicating that the data is displayed in sort order.
5. On the Home tab, in the Sort & Filter group, click the Remove Sort button. The sort is
removed from the Customer ID field.
6. Select the First Name field. On the Home tab, in the Sort & Filter group, click the
Ascending button. The data in the First Name field is sorted in ascending order.
7. Select the Last Name field. On the Home tab, in the Sort & Filter group, click the
Ascending button. The data in the Last Name field is sorted in ascending order.
8. On the Home tab, in the Sort & Filter group, click the Remove Sort button. The sort is
removed from both the First Name and Last Name fields.
2.3.2
9. Close the table. If a dialog box appears asking if you want to save changes to the
How do you sort data table, click No.
within a table? PAUSE. LEAVE the database open to use in the next exercise.
3. Point to Text Filters. A second menu appears. Select Contains, as shown in Figure 3-16.
Figure 3-16
Filter menu with
Contains selected
4. The Custom Filter box appears. Key Decaf, as shown in Figure 3-17, and click OK.
Access filters the database to display only the records containing the word Decaf. A
filter icon is displayed in the header row of the field, as shown in Figure 3-18.
Figure 3-17
Custom filter box
Figure 3-18
Filtered records
Filter
icon
5. Click the Toggle Filter button in the Sort & Filter group to display the records without
the filter.
6. In the second record in the Product Name field, double-click the word Decaf to
select it.
7. Right-click the word Decaf to display the shortcut menu. Select Does Not Contain
“Decaf,” as shown in Figure 3-19. Notice that the records are filtered to show only
those that do not contain the word Decaf.
64 Lesson 3
Figure 3-19
Shortcut menu with Does
Not Contain “Decaf”
option selected
Figure 3-20
Filter menu selected
to show only 25 in the
pounds column
11. Click OK. Access filters the records to show only those containing the number 25 in
the pounds field.
12. Click the Toggle Filter button.
13. In the second row of the Scheduled Order Date field, highlight 1/14/2012 by clicking
and dragging the mouse.
14. On the Home tab, in the Sort & Filter group, click the Selection button. A menu
appears, as shown in Figure 3-21.
15. Select On or After 1/14/2012. The data is filtered to show only those records with
content in the Scheduled Order Date field that matches the filter selection.
2.3.3
16. In the seventh row of the Pounds field, select 30.
How do you filter 17. On the Home tab, in the Sort & Filter group, click the Selection button. Select
table records? Less Than or Equal to 30. The records are filtered.
PAUSE. LEAVE the database open to use in the next exercise.
Work with Tables and Database Records 65
Take Note Only one filter can be applied per column. When you apply a filter to a column that is already
filtered, the previous filter is removed and the new filter is applied.
Removing a Filter
After applying a filter, you may need to return to records not displayed by the filter. The Toggle
Filter button lets you switch between viewing the filtered records and viewing the table without
the filter. Note that the purpose of this button changes accordingly—when the records are filtered
the button is used to remove the filter, and when the filter is removed the button is used to apply
the filter. When you are finished using the filter, you can permanently remove it. In this exercise,
you permanently remove the filter you previously applied.
Figure 3-22
Removing filter from the
pounds column
3. On the Home tab, in the Sort & Filter group, click the Advanced Filter Options button.
A menu appears.
4. Select Clear All Filters from the menu, as shown in Figure 3-23.
3. Select Freeze Fields. Notice that the Last Name field moves to the first field position in
the table.
4. Click the Restore Down button in the top, right corner of the application window, as
shown in Figure 3-25. The Restore Down button now becomes the Maximize button.
Press the Right Arrow key to scroll the table’s fields to the left, and stop when you
reach the ZIP/Postal Code field. Notice that the Last Name field stays fixed as the other
fields scroll.
Figure 3-25
Restore down button
5. Click the More button again and select Unfreeze All Fields. Notice how the Last Name
field remains in the table’s first field position. Press the Right Arrow key several times
until the Last Name field scrolls off from view. Notice how the Last Name field moved
with the other fields when the Right Arrow key was pressed several times.
Take Note Fields can be rearranged in Datasheet View by clicking on the field name headers and dragging
them to where you want to move them.
Figure 3-26
Hidden Customer ID field
8. Click the More button and select Unhide Fields. The Unhide Columns dialog box
should appear as shown in Figure 3-27. Notice the check mark is missing from the
Customer ID check box, signifying that it’s hidden.
Figure 3-27
Unhide Columns dialog box
Customer ID field
representation
is unselected
2.2.5
How do you freeze or
unfreeze fields?
9. Deselect the check boxes next to all the other field representations except Last Name
and Business Phone, and then click the Close button in the Unhide Columns dialog
2.2.4 box. Notice the only fields now displayed in Datasheet View are the Last Name and
Business Phone fields.
How do you hide or 10. Close the Customers table without saving the changes to the layout.
unhide fields? PAUSE. LEAVE the database open to use in the next exercise.
Take Note You can save your table so it retains your formatting the next time you open it.
Take Note To select more than one field to freeze or hide, hold down the shift key while selecting
adjacent fields.
Another Way
You can also access
the Hide/Unhide and Freeze/
Unfreeze options from the
shortcut menu that appears
after you right-click a field name.
68 Lesson 3
SOFTWARE ORIENTATION
Displays all
database
relationships
and tables
Click to create
relationship
Common field
for each table
70 Lesson 3
6. Select the Enforce Referential Integrity check box. Then select the Cascade Update
Related Fields and Cascade Delete Related Records check boxes.
7. Click Create. A relationship line representing the one-to-many table relationship of the
Customers and the Order Summary tables is displayed, as shown in Figure 3-31. You
just created a one-to-many relationship between these tables using Customer ID, the
common field. The one-to-many relationship type signifies that each customer record
in the Customers table can have many order records in the Order Summary table.
2.4.2
How do you use primary keys
to create relationships? PAUSE. LEAVE the database open to use in the next exercise.
To remove a table relationship, you must delete the relationship line. You can select the line by
pointing to it and clicking it. When the relationship line is selected, it appears thicker. Press the
Delete key to delete the line and remove the relationship or right-click the line to display the
delete menu.
Figure 3-32
Edit/Delete menu
2. Select Delete. A message appears asking if you are sure you want to delete the
relationship. Click Yes. The line disappears.
3. Select the Customer ID field in the first table. Drag the mouse to the Customer ID field
in the second table and release the mouse button. The Edit Relationships dialog box
appears.
4. Click the Create button. A line appears, creating the relationship.
5. Double-click the center section of the relationship line. The Edit Relationships dialog
box appears again, listing the tables and the Customer ID fields on each side.
6. Click the Enforce Referential Integrity box and click OK. The line appears thicker, with
the number 1 beside the first table and the infinity symbol () beside the second, as
shown in Figure 3-33.
SKILL SUMMARY
In This Lesson Objective
You Learned How To: Exam Objective Number
Navigate among Records
Enter, Insert, Edit, and
Delete Records
Work with Primary Keys Define Primary Keys. 2.4.1
Find and Replace Data Use Find. 2.3.1
Attach and Detach Documents
Sort and Filter Data and Set Field Use Sort. 2.3.2
View Options within a Table Use Filter commands. 2.3.3
Freeze or Unfreeze fields. 2.2.5
Hide or Unhide fields. 2.2.4
Understand Table Relationships Use Primary Keys to create 2.4.2
Relationships.
Edit Relationships. 2.4.3
Knowledge Assessment
Matching
Match the term in Column 1 to its description in Column 2.
Column 1 Column 2
1. foreign key a. prevents orphan records, to ensure that records do not
reference other records that no longer exist
2. composite key b. sorts data from beginning to end
3. outermost field c. sorts data from end to beginning
4. referential integrity d. to arrange data alphabetically, numerically, or
chronologically
5. wildcards e. a primary key from one table that is used in another table
6. ascending order f. a set of rules for determining which records will be
displayed
7. descending order g. the secondary sort field in a multifield sort
8. filter h. two or more primary keys in a table
9. sort i. characters used to find words or phrases that contain
specific letters or combinations of letters
10. innermost field j. the primary sort field in a multifield sort
74 Lesson 3
True/False
Circle T if the statement is true or F if the statement is false.
T F 1. You can use the Navigation buttons to search for data in a table.
T F 2. You can enter any kind of data into any field.
T F 3. After you enter data and move to a new field, Access automatically saves the
data for you in the table.
T F 4. After you delete a record, you can click the Undo button to bring it back.
T F 5. The Find and Replace dialog box searches all the tables in a database at
one time.
T F 6. An AutoNumber field will usually make a good primary key.
T F 7. Before you can attach a document, there must be a field in a table formatted
with the Attachment data type.
T F 8. The outermost field is the primary sort field in a multifield sort.
T F 9. The Toggle Filter button lets you permanently remove a filter and switches you
back to the original view.
T F 10. In a one-to-many relationship, each record in the first table can have many
records in the second table.
Competency Assessment