-
On the Database Tools
tab, in the Relationships
group, click the Relationships
button.
The Relationships page shows that in this database,
there is a relationship between the Customers and Orders tables
and between the Employees and Orders tables. You want to create
Customer and Employee lookup fields in the Orders table, so you
first need to delete the existing relationships.
-
Right-click the diagonal part of the line between the
Customers and Orders tables, and click Delete, clicking Yes to confirm the deletion. Repeat this
step for the line between the Employees and Orders tables. Then close the Relationships page, clicking Yes to save the change.
Tip
If you want to remove a table’s box from the Relationships
page, you can right-click the box and click Hide Table. If you
want to remove all the boxes, you can click the Clear Layout
button in the Tools group on the Design contextual tab.
-
Open the Orders table,
and drag across the CustomerID
and EmployeeID field names to
select those fields. On the Fields contextual tab, in the Add & Delete group, click the
Delete button. Then click
Yes to permanently delete the
fields and Yes to delete their
indexes.
Now we’ll add a new Employee lookup field.
-
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 and displays its first page.
-
With I want the lookup field to get
the values from another table or query selected, click
Next.
The Lookup wizard asks you to identify the table on which
the lookup field will be based.
-
Click Table: Employees in
the list, and click Next.
-
On the next page, in the Available
Fields list, double-click EmployeeID, then FirstName, and then LastName to transfer those fields to the
Selected Fields list. Then
click Next.
-
On the next page, click the arrow for the first sort box,
click LastName in the list, and
then click Next.
The wizard displays the lookup list with the EmployeeID
field (the key column) hidden.
-
Click Next. On the
wizard’s last page, type Employee as the name of the field, and
select the Enable Data
Integrity check box. Then click Finish.
-
Click in the Employee
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.
-
Click Nancy Anderson to
enter the name Nancy as the salesperson for
this order.
Now let’s work with the Customers table. First we want to
change the primary key for this table.
-
Open the Customers table in Design view. On the
Design contextual tab, in the
Tools group, click the
Primary
Key button to turn it off. Then change the Data Type setting for the CustomerID field to Text.
-
Change the Field Size
property to 5, and enter an
Input Mask property of
>LLLLL;;.
This input mask will force Access to display the CustomerID
in capital (uppercase) letters, no matter how it is
entered.
-
Click the CustomerID
field in the Field Name column,
and in the Tools group, click
the Primary Key button. Then
save the table.
-
Switch to Datasheet view. For each customer, assign a
CustomerID that consists of the
first three letters of the last name and the first two letters of
the first name.
Even if you type the ID in all lowercase letters, Access
displays them in uppercase.
-
Sort the table in ascending order on the CustomerID field, and then close it,
clicking Yes to save your
changes.
-
In the Orders table, use
the Lookup wizard to create a new lookup field based on the
CustomerID, FirstName, and LastName fields of the Customers table. Sort the lookup list on
LastName, and then click
Next.
-
On the page that asks you to adjust the width of the columns
in the lookup field, point to the right border of the FirstName field name, and when the
pointer changes to a double-headed arrow, drag all the way to the
left to hide that column. Click Next.
-
Name the field Customer,
and enforce referential integrity. Then click Finish.
Now try entering an order for Pilar Ackerman.
-
In the Customer field of
the first record, type ack.
Ackerman is the only LastName value
beginning with those letters, so Access completes the entry for
you.
-
Click the field in the record below.
Access enters the name Ackerman as it
appears in the Customers table.
-
In the active record, type c.
Access enters campbell, the first
LastName value beginning with c in the
Customers table. This is not the customer we want.
-
Click the arrow at the right end of the field.
Access displays the list with Campbell highlighted.
-
Click Cox, and press Tab.
Then close the Orders
table.
-
On the Database Tools
tab, in the Relationships
group, click the Relationships
button.
The Lookup wizard automatically created one-to-many
relationships between the Customers and Orders tables and between
the Employees and Orders tables.