5. Restricting Data to Values in Lists
It is interesting how many different ways people can
come up with to enter the same items of information in a database.
Asked to enter the name of their home state, for example, residents of
the state of Washington will type Washington,
Wash, or WA, plus various
typographical errors and misspellings.
Minor inconsistencies in the way data is entered might not be
really important to someone who later reads the information and makes
decisions. For example, Arizona and
AZ refer to the same state. But a computer is
very literal, and if you tell it to create a list so that you can send
catalogs to everyone living in AZ, the computer
won’t include anyone whose state is listed in the database as
Arizona.
You can limit the options for entering information in a database
in several ways:
-
If one entry is more likely than any other, you can set the
Default Value property of the field to that entry. Users can then
press Tab to skip over that field, leaving the default entry
intact. Even if users enter something else, the format of the
default entry might guide them when choosing their entry’s
format. -
For only two options, you can use a Yes/No field represented
by a check box. A check in the box indicates one choice, and no
check indicates the other choice. -
For a short list of choices that won’t change often, you can
use a combo box. Clicking the arrow at the right end of the combo
box displays the list of choices, which you provide as a lookup
list. Depending on the properties associated with the combo box,
database users might be able to type something else or they might
be able to add entries to the lookup list displayed in the future.
Although you can create a lookup list by hand, it is a lot easier
to use the Lookup wizard.
Tip
Access comes with three Quick Start lookup lists that are
commonly used in businesses: Payment Type, Priority, and Status. You
can efficiently add one of these ready-made lookup lists to a table
by clicking the More Fields button in the Add & Delete group on
the Fields contextual tab, and then clicking the field you
want.
In this exercise, you’ll use the Lookup wizard to create a list
of states and provinces from which users can choose.
Set Up
You need the GardenCompany06 database you worked with in the
preceding exercise to complete this exercise. Open the
GardenCompany06 database, and display the FieldTest table in
Datasheet view. Then follow the steps.
-
At the right end of the table, click the Click to Add field. On the Fields contextual tab, in the Add & Delete group, click the
More Fields button, and then
click Lookup &
Relationship.
The Lookup wizard starts.
If a field has a lot of potential entries, or if they will
change often, you can link them to a table. (You might have to
create a table expressly for this purpose.) If a field has only a
few possible entries that won’t change, typing the list directly
in the wizard is easier.
-
Click I will type in the values that
I want, and then click Next. -
Leave the number of columns set to 1, and click in the first cell in the
Col1 column. -
Enter the following state and province abbreviations,
pressing Tab (not Enter) after each one to move to a new
row.
BC
CA
ID
MT
OR
WA
-
Click Next.
The wizard needs a little more information before it can
create the field.
-
Type fLookup as the name
of the field, and select the Limit To
List check box. Then click Finish. -
Save the table, and switch to Design view. -
Click anywhere in the fLookup field, and then in the Field Properties area, click the
Lookup tab.
The Lookup page shows the properties that control the lookup
list. -
In the Field
Properties area, click the General tab. Then click anywhere in the
Default Value property, type
WA, and press Enter. -
Switch to Datasheet view, clicking Yes to save your changes to the
table.
The entry WA appears in the fLookup
field of the new record. -
Click in the fLookup
field of the first record, and then click the arrow at the right
end of the field.
The list of possible entries for this field appears.
Tip
Clicking the button that appears below the options list
opens the Edit List Items dialog box. If you don’t want users to
be able to edit the list, you can disable this property, as we
do later in this exercise.
-
Click MT to enter the
abbreviation for Montana in the field. -
With MT selected, type
b.
Access completes the entry by displaying
C. -
Click the record below.
Access converts bC to
BC. -
Select BC, type Utah, and press Tab. Then when Access
tells you that the entry isn’t in the list and asks whether you
want to edit the list, click Yes. -
When the Edit List Items
dialog box opens, click Cancel,
and then click BC in the
list. -
Switch to Design view, and click the Lookup tab.
The Limit To List property on the Lookup page for the
fLookup field is set to Yes, but the Allow Value List Edits
property is also set to Yes, meaning that users can change the
list. -
Click the Allow Value List
Edits property, click the arrow that appears, and then
click No. -
Save the table, return to Datasheet view, type
Utah in the fLookup field, and then press Tab.
Access informs you that the text you entered is not in the
list. -
Click OK to close the
message box. Then click BC in
the list, and press Tab.
Clean Up
Close the FieldTest table. Retain the GardenCompany06 database
for use in the last exercise.
|