Notes 4 - Modifying Tables and Fields
Notes 4 - Modifying Tables and Fields
KEY TERMS
• input mask
• multivalued field
• properties
• Quick Start field
• validation rule
• validation text
• zero-length string
78
Modify Tables and Fields 79
GET READY. Before you begin these steps, be sure to launch Microsoft Access.
1. OPEN the Events database from the data files for this lesson.
The Events file for 2. SAVE the database as EventsXXX (where XXX is your initials).
this lesson is available 3. Click the Close ‘Event List’ button to close the form that displays.
on the book companion
4. In the Navigation Pane, double-click Events to open that table.
website or in WileyPLUS.
5. On the Home tab, in the Views group, click the Views button and then click
Design View.
6. On the Design tab, in the Show/Hide group, click Property Sheet. The Property Sheet
pane appears on the right of the Access window, as shown in Figure 4-1.
WileyPLUS Extra! features an
online tutorial of this task.
80 Lesson 4
Figure 4-1
Property sheet pane
7. Place the insertion point in the property box for Description.
8. Press Shift+F2 to open the Zoom box, shown in Figure 4-2, to provide more space.
Figure 4-2
Zoom dialog box
9. Key Most popular events for 2012.
10. Click OK.
Another Way 11. Click the Close button on the Property Sheet pane to close it.
You can also press
Alt+Enter to display the 12. Click the File tab and click Save to save the design changes you’ve made to the table.
property sheet for an object. PAUSE. LEAVE the database open to use in the next exercise.
To set the properties for a table, open the table in Design View. On the Design tab, in the Show/
Hide group, click Property Sheet. Click the box for the property you want to set and key a
setting for the property. Table 4-1 lists the available table properties and what they control.
Modify Tables and Fields 81
Table 4-1
Table Property Use This Table Property To
Table Properties
Subdatasheet Expanded Specify whether to expand all subdatasheets when you open the table.
Subdatasheet Height Specify whether to expand to show all available subdatasheet rows
(default) when opened or to set the height of the subdatasheet window
to show when opened.
Orientation Set the view orientation, according to whether your language is read
left-to-right or right-to-left.
Description Provide a description of the table.
Default View Set Datasheet, PivotTable, or PivotChart as the default view when you
open the table.
Validation Rule Supply an expression that must be true whenever you add a record or
change a record.
Validation Text Enter text that appears when a record violates the Validation Rule
expression.
Filter Define criteria to display only matching rows in Datasheet View.
Order By Select one or more fields to specify the default sort order of rows in
Datasheet View.
Subdatasheet Name Specify whether a subdatasheet should appear in Datasheet View, and,
if so, which table or query should supply the rows in the subdatasheet.
Link Child Fields List the fields in the table or query used for the subdatasheet that
match this table’s primary key field(s).
Link Master Fields List the primary key field(s) in this table that match the child fields for
the subdatasheet.
Filter On Load Automatically apply the filter criteria in the Filter property (by setting
to Yes) when the table is opened in Datasheet View.
Order By On Load Automatically apply the sort criteria in the Order By property (by
setting to Yes) when the table is opened in Datasheet View.
Order By On Provide an alternate method to the Order By On Load property by
automatically applying the sort criteria in the Order By property when
set to -1 (Yes).
Renaming a Table
To rename a table or other database object, you must first close it. In the Navigation Pane,
locate and right-click the object that you want to rename, and then click Rename on the shortcut
menu that appears. Or, select the table in the Navigation Pane, press F2, key a new name, and
press Enter. Think carefully before you rename a table. If existing database objects, such as queries
or reports, use data from that table, the name modification might break the functionality of the
database. In this exercise, you create a new table and then rename it using the shortcut menu.
3. Open the Comments table and right-click Comments in the Navigation Pane to display
the shortcut menu shown in Figure 4-3. Select Rename and a dialog box appears that
states You can’t rename the database object ‘Comments’ while it’s open, as shown in
Figure 4-4. Close the dialog box.
Figure 4-3
Rename command on table
shortcut menu
Right-click
to display
shortcut
menu
Rename
command
Figure 4-4
Can’t rename table dialog box
Figure 4-5
Table name selected
for renaming
Key new
table name
1.2.1
7. Key Event Comments and press Enter. The table has been renamed.
How do you rename a
database table? PAUSE. LEAVE the database open to use in the next exercise.
Modify Tables and Fields 83
Deleting a Table
Deleting an entire table is not a complex process; however, remember that when you delete an
entire table you might break the functionality of your database. Although you will be asked to
confirm the deletion of a table, you can always undo the action. In this exercise, you delete a table.
To delete a table or other database object like a report, form, or query, right-click it in the Navi-
gation Pane and click Delete. Or, select the table in the Navigation Pane and press Delete.
Figure 4-6
Delete table confirmation
message
Take Note If the table was related to one or more additional tables, Access would ask if you wanted to delete
those relationships before deleting the table.
1.2.2
PAUSE. LEAVE the database open to use in the next exercise.
How do you delete objects?
Ref Another way to remove data is to delete information from individual records or delete entire
records from a table, as you learned in Lesson 3.
SOFTWARE ORIENTATION
Field Properties
Some field properties are available in Datasheet View, but to access the complete list of field
properties you must use Design View. An example of field properties for a table in Design
View is shown in Figure 4-7.
Selected field
Field properties
for selected field
Figure 4-7
Field properties Use this figure as a reference throughout this lesson as well as the rest of this book.
84 Lesson 4
Take Note The maximum number of characters you can enter into a field is 255.
STEP BY STEP Set a Field Property in Datasheet View and Design View
Figure 4-8
4. On the Home tab, in the Views group, click the View button and click Design View.
Table Tools Tab
5. In the Field Name column in the upper portion of the table design grid, click in the
Title cell.
2.2.8 6. In the Field Size row in the lower portion of the table design grid, select 150 in the
property box and key 175 to change the maximum number of characters you can enter
How do you modify field in the Title field.
properties?
PAUSE. LEAVE the database open to use in the next exercise.
Table 4-2
Field Property Use This Field Property To
Available Field Properties.
Field Size Set the maximum size for data stored as a Text, Number, or AutoNumber
data type.
Format Customize the way the field appears when displayed or printed.
Decimal Places Specify the number of decimal places to use when displaying numbers.
New Values Set whether an AutoNumber field is incremented or assigned a random
number.
Input Mask Display editing characters to guide data entry.
Caption Set the text displayed by default as the column name in tables and labels
for forms, reports, and queries.
Default Value Automatically assign a default value to a field when new records are added.
Validation Rule Supply an expression that must be true whenever you add or change the
value in this field.
Validation Text Enter text that appears when a value violates the Validation Rule.
Required Require that data be entered in a field.
Allow Zero Length Allow entry (by setting to Yes) of a zero-length string (““) in a Text, Memo,
or Hyperlink field.
Indexed Speed up access to data in this field by creating and using an index.
Unicode Compression Compress text stored in this field when a large amount of text is stored.
IME Mode Specify an Input Method Editor, a tool for using English versions of Windows.
IME Sentence Mode Specify the type of data you can enter by using an Input Method Editor.
SmartTags Attach a smart tag to this field.
Append Only Allow versioning (by setting to Yes) of a Memo field.
Text Format Choose Rich Text to store text as HTML and allow rich formatting.
Choose Plain Text to store only text.
Text Align Specify the default alignment of text within a control.
Precision Specify the total number of digits allowed, including those both to the
right and the left of the decimal point.
Scale Specify the maximum number of digits that can be stored to the right of
the decimal separator.
86 Lesson 4
Figure 4-9
Input Mask Wizard button
Click to
open Input
Mask Wizard
3. Click the Input Mask Wizard button. A message box appears asking if you want to save
the table now.
Modify Tables and Fields 87
4. Click Yes to close the message box and display the Input Mask Wizard, as shown in
Figure 4-10.
Figure 4-10
Input Mask Wizard
5. Click Medium Date, to select the DD-MON-YR date format, and then click Next >. The
next screen in the Input Mask Wizard appears, as shown in Figure 4-11.
Figure 4-11
Input Mask Wizard, next screen
Input mask pattern
that Wizard creates
for you can also be
manually entered
6. Click Next to accept the default settings in this screen and display the final Input Mask
Wizard screen, as shown in Figure 4-12.
Figure 4-12
Input Mask Wizard, final screen
88 Lesson 4
7. Click Finish. The input mask appears in the Input Mask row, as shown in Figure 4-13.
Figure 4-13
Input Mask row
Click to
display
menu
Figure 4-14
Zero Length property menu 4. Click Yes.
PAUSE. LEAVE the database open to use in the next exercise.
Take Note By default, when you try to position the pointer in a Memo field with the Append Only property
enabled, Access hides the text.
June 4, 1977.” The maximum length for the Validation Text property is 255 characters. In this
exercise, you modify the Validation Rule and Validation Text properties for the End Time field.
Data can be validated in several ways, and you will often use multiple methods to define a valida-
tion rule. Each of the following can be used to ensure that your users enter data properly:
• Data types: When you design a database table, you define a data type for each field in
the table, and that data type restricts what users can enter. For example, a Date/Time field
accepts only dates and times, a Currency field accepts only monetary values, and so on.
• Field sizes: Field sizes provide another way to validate text. For example, if you create a
field that stores first names, you can set it to accept a maximum of 15 characters. This can
prevent a malicious user from pasting large amounts of text into the field. It could also
prevent an inexperienced user from mistakenly entering a first, middle, and last name in a
field designed only to hold a first name.
• Table properties: Table properties provide very specific types of validation. For
example, you can set the Required property to Yes, and, as a result, force users to enter
a value in a field.
Another Way
As you already • Field properties: You can also use field properties, such as the Validation Rule property to
learned in this lesson, you require specific values, and the Validation Text property to alert your users to any mistakes.
can also use the Input Mask For example, entering a rule such as ⬎1 and ⬍100 in the Validation Rule property forces
property to validate data by users to enter values between 1 and 100. Entering text such as “Enter values between 1 and
forcing users to enter values in 100” in the Validation Text property tells users when they have made a mistake and how to
a specific way. fix the error.
Figure 4-15
Expression Builder button
3. Click the Expression Builder button to display the Expression Builder dialog box, as
shown in Figure 4-16.
Figure 4-16
Expression Builder dialog box
Figure 4-17
Modified Validation field
properties
Entering Captions
The Caption property field specifies the text displayed by default as column names in tables and
in labels for forms, reports, and queries. The maximum length for the Caption property is 255
characters. If you don’t specify a caption to be displayed, the field name is used as the label. In
this exercise, you set the Caption property for the Location field.
92 Lesson 4
SOFTWARE ORIENTATION
Use this figure as a reference throughout this lesson as well as the rest of this book.
Creating Fields
Fields can be created in different ways. You can add fields to a table in Design View, or add fields
in Datasheet View using the Click to Add column and Add & Delete Group. Sometimes it is
easier to choose from a predefined list of fields than to manually create a field. Access includes a
quick and easy way for you to add fields to a table using the Add & Delete group on the Table
Tools Fields contextual tab, which includes a collection of fields with associated data types and
built-in Quick Start fields that can save you considerable time. In this exercise, you add fields to
a table by using a combination of the Click to Add column and the Add & Delete group.
The last column in a table in Datasheet View has a Click to Add column, which you can use to
add a field simply by keying information in that column. Rename the field by right-clicking the
column head, choosing Rename Field from the menu, and keying a new name. Access will try
to automatically determine the field data type by the data entered.
A Quick Start field is a predefined set of characteristics and properties that describes a field,
including a field name, a data type, and a number of other field properties. Quick Start fields are
NEW new to Access 2010 and allow you to quickly add commonly used single fields or several related
to Office 2010 ones. For example, using Quick Start fields, you can choose from a variety of fields including
“Status” to quickly add a field named Status with built-in options like Not Started, In Progress,
and so on, or you can choose the “Address” Quick Start to quickly include related fields like City,
State, and Zip Code.
Modify Tables and Fields 93
To create a new field, you can simply choose from commonly used fields in the Add & Delete
group, or click the More Fields button to access a menu with a greater variety of field types. To
create a new field using Quick Start, click the More Fields button and then choose a Quick Start
field from the menu, as shown in Figure 4-19.
Figure 4-19
More Fields button menu Click button to
display menu
Additional
Fields
Quick
Start fields
3. Key Yes and press Enter. A new field named Field1 is added, and the Click to Add
column becomes the last column in the table, as shown in Figure 4-21.
4. Right-click the Field1 column header to display the shortcut menu and click Rename
Field, as shown in Figure 4-22.
7. In the Yes/No category, click Check Box. A new field with check boxes is created in the
table, as shown in Figure 4-24.
8. Click the Name & Caption button in the Properties group, which is shown in Figure 4-25.
The Enter Field Properties dialog box appears.
9. Key Souvenirs in the Name box and press Enter. Notice the column has been renamed
Souvenirs.
10. Scroll to the right of the Events table to display the last column and click in the first
cell below the Click to Add header.
11. Click the More Fields button in the Add & Delete group on the Table Tools Fields
contextual tab to view the More Fields menu.
12. In the Quick Start category, click Status. A new Quick Start field named Status, in
which you now have options to indicate the status of the event, appears to the right of
the Souvenirs field, as shown in Figure 4-26.
Figure 4-26
Status field created
13. Click the Status field drop-down arrow button to view the available options, and click
2.2.3 Not Started, as shown in Figure 4-27.
Not Started
option
selected
Figure 4-27
Status field drop-down
box options
Deleting a Field
1.3.2 Before you delete a column from a datasheet, remember that doing so deletes all the data in the
column and that the action cannot be undone. For that reason, you should back up the table
How do you use Quick Start before you delete the column. Before you can delete a primary key or a lookup field, you must
to add fields? first delete the relationships for those fields. In this exercise, you learn how to use the shortcut
commands to delete a field from an Access 2010 table.
To delete a field in Datasheet View, select the column, right-click, and then click Delete Field
Another Way from the shortcut menu. Or, on the Table Tools Fields contextual tab in the Add & Delete
You can also quickly group, click the Delete button. You will see a confirmation message asking if you are sure you
add fields by accessing the Click
want to delete the column and all the data. Sometimes you may see an additional confirmation
to Add column menu on the
right side of the Click to Add
message warning you about potential issues when deleting fields. You should always be cautious
column header. when deleting fields from a table.
2.2.2
How do you delete a field?
Another Way
You can also delete Delete field command
a field by clicking the Delete
button on the Table Tools Fields
contextual tab in the Add & 3. A message appears, as shown in Figure 4-29. Click Yes.
Delete group.
Figure 4-29
Delete field message
98 Lesson 4
4. A confirmation message appears, as shown in Figure 4-30. Click Yes. The field is deleted.
Figure 4-30
Delete field confirmation
message
Take Note You can also create lookup columns that allow for a single selection of a value.
Figure 4-31
Lookup Wizard
Modify Tables and Fields 99
2. Click Next > to accept the default setting (I want the lookup field to get the values from
another table or query) and display the next screen in the Lookup Wizard, as shown in
Figure 4-32. Notice you have a choice of two tables to provide the values for the lookup
field you’re creating. The first table, Employees, should already be selected for you.
Figure 4-32
Lookup Wizard, second screen
3. Click Next > to accept the default settings and display the next screen in the Lookup
Wizard, as shown in Figure 4-33. The Available Fields scroll box contains all the fields
of the Employees table, two of which you will select since they contain the values you
want to eventually look up.
Figure 4-33
Lookup Wizard, third screen
4. In the Available Fields list, select Last Name, then click the > button to move it to the
Selected Fields box.
5. In the Available Fields list, select First Name, then click the > button to move it to the
Selected Fields box.
6. Click Next > to accept your settings and display the next screen in the Lookup Wizard.
7. Click the down arrow in the first box and click Last Name, as shown in Figure 4-34.
This will sort the Lookup column in alphabetical order by Last Name.
Figure 4-34
Lookup Wizard, fourth screen
100 Lesson 4
8. Click Next > to accept your selection and to display the next screen in the Lookup
Wizard, as shown in Figure 4-35.
Figure 4-35
Lookup Wizard, fifth screen
9. Click Next > to accept the default selection and to hide the primary key column to
ensure only relevant and meaningful data displays in the lookup column later. The
final screen of the Lookup Wizard displays, as shown in Figure 4-36.
Figure 4-36
Lookup Wizard, final screen
10. In the What label would you like for your lookup field? box, key Coordinator. This will
create a new label named Coordinator for your column.
Another Way
You can also 11. Select the Allow Multiple Values check box to allow for the multiple selection of values.
modify the Allow Multiple 12. Click the Finish button. A new column named Coordinator appears after the ID field.
Values property in the Lookup Click the down arrow in the first cell to display the list of names, as shown in
Field Properties sheet in table Figure 4-37.
Design View.
Figure 4-37
Lookup column list
Click down
arrow to display
list of names
13. Click Flood/Kathie and Mares/Gabe on the list and then click OK to choose those
multiple values for the field.
STOP. CLOSE the database.
Troubleshooting Consider using a multivalued field only when you are relatively sure that your database
will not be moved to a Microsoft SQL Server at a later date. An Access multivalued field is
upsized to SQL Server as a memo field that contains a delimited set of values. Because SQL
Server does not support a multivalued data type, additional design and conversion work
might be needed.
SKILL SUMMARY
In This Lesson Objective
You Learned How To: Exam Objective Number
Modify a Database Table Rename objects. 1.2.1
Delete objects. 1.2.2
Create Fields and Modify Modify field properties. 2.2.8
Field Properties Rename a field. 2.2.3
Insert a field. 2.2.1
Use Quick Start. 1.3.2
Delete a field. 2.2.2
Knowledge Assessment
Multiple Choice
Select the best response for the following statements or questions.
Competency Assessment
The Customer 1. OPEN Customer service from the data files for this lesson.
service file for this lesson is 2. SAVE the database as Customer service XXX (where XXX is your initials).
available on the book companion
3. Close the Case List form that is open.
website or in WileyPLUS.
4. In the Navigation Pane, double-click the Calls table to open it. Place the insertion point
in the first cell of the table, if necessary.
5. On the Table Tools Fields contextual tab, in the Add & Delete group, click the More
Fields button and then click the Lookup & Relationship button. The Lookup Wizard
appears.
6. Click Next > to display the next screen in the Lookup Wizard.
7. Select Table: Employees and click Next >.
8. In the Available Fields list, select First Name, then click the > button to move it to the
Selected Fields box.
9. In the Available Fields list, select Last Name, then click the > button to move it to the
Selected Fields box.