Microsoft Access Training

Lookup Fields and Validation Rules

Learn to create lookup fields that display meaningful values while storing keys, and add a table validation rule that compares departure and return dates.

Start here

Overview

This lesson adds a Destinations table, converts key fields in TblTrips into lookup fields, and creates a table-level validation rule requiring the departure date to occur before the return date.

What You Will Learn

  • Create and populate a destination lookup table.
  • Use the Lookup Wizard to create a lookup field from a table or query.
  • Choose lookup fields and sort their displayed values.
  • Hide the key column while retaining the stored key.
  • Create lookup fields for DestinationID, ClientID, and AgentID.
  • Create a table-level validation rule involving two fields.
  • Create validation text that explains an invalid date combination.

Before You Begin

  • Creating and relating Access tables
  • Primary and foreign keys
  • Table Design View
  • Basic field properties

Why This Matters

Lookup fields make key-based data easier to enter, while table validation rules protect relationships among fields that cannot be checked by validating one field alone.

Plan Your Study

  • Create and populate TblDestinations.
  • Open TblTrips in Design View.
  • Create the DestinationID lookup field.
  • Create the ClientID and AgentID lookup fields.
  • Open the table Properties Sheet.
  • Add the departure-before-return validation rule and its message.
  • Save and test the table.

Next step

Read the complete chapter.

The Learn tab contains the written lesson from Surviving Statistics.

Go to Learn

Written lesson

Learn Lookup Fields and Validation Rules

Learn to create lookup fields that display meaningful values while storing keys, and add a table validation rule that compares departure and return dates.

Advertisement

Lookup Fields and Validation Rules

Much of the power in an Access database comes when you intitally set it up. One of the essential elements of proper database design is understanding how to use Access' Lookup Fields and Validation Rules. This lesson will step you through modifying Lookup Fields and Validation Rules

Lookup Fields and Validation Rules

A lookup field creates a dropdown list, which makes entering and editing data much easier. Instead of having to type the data into the field, you will be able to click on a option from a list of choices. Along with being faster, lookup fields also help ensure data integrity since you will only be able to choose from a value in the dropdown list.

You can create lookup fields on forms or tables. One advantage of creating lookup fields in tables is that when you create a form based on that table, the lookup fields will automatically be included on the form. In addition, if you enter or edit data on the table directly using the Datasheet View, the lookup fields in the table will make entering data there easier.

The values for the dropdown list can be manually entered when the lookup field is created or the data can be obtained from another table. Using a table is the best choice because if you need to edit or add additional items to the dropdown list, editing existing values on or adding new records to a table is easy. If you enter the items directly into the list control, changes would require that you edit the control and add or revise the items in the list. This adds a level of complexity and an additional skill you would have to learn. Using a table as the basis of a drop down list means all you have to do is open the table and make the changes. Those changes will show up in the drop down list in the table or form.

In this lesson, you will create a new table that contains the trip destinations which can be booked through this travel agency. This table will provide the values for a dropdown list which is used when new trips are scheduled for clients.

1. Open the No Fault Travel database, if needed and create another table named TblDestinations with the fields as shown.

Microsoft Access lesson screenshot 2ndLesson1

This table will link to the Trips table using the DestinationID field.

Although your goal is to create a dropdown list of the destinations, two fields will be included in the new table, DestinationID and Destination. DestinationID provides a unique identification number for each destination; it is the primary key with an AutoNumber data type. The destination will be visible in the field, but it is actually storing the primary key, DestinationID.

Microsoft Access lesson screenshot 2ndLesson2

2. Enter the records as shown into the Destinations table and then close it.

You will now link the destination field in the trips table to the DestinationID field in the destinations table. You will begin this process by entering design view.

3. Open TblTrips in Design View.

Creating a lookup field

Access makes it very easy to create a lookup field using the Lookup Wizard. You will do this by using the Lookup wizard.

Microsoft Access lesson screenshot 2ndLesson3

4. Click the drop down list button in the data type column of the DestinationID field. Then, select Lookup Wizard from the list of choices.

Access will open the Lookup Wizard. The Lookup Wizard will guide you through the creation of a lookup field.

5. In the first step of the Lookup Wizard, be sure that the first option, “I want to look up values in a table or query”, is selected and click Next.

Microsoft Access lesson screenshot 2ndLesson4

You will now select the table or query that contains the list of values you want displayed when you click the dropdown arrow for this field.

6. In this step of the Lookup Wizard, choose TblDestinations and click Next.

Microsoft Access lesson screenshot 2ndLesson5

Next, you will select which fields from the table to display in the dropdown list. In this case, you will select both fields, DestinationID and Destination. The DestinationID will actually be stored in the field, but you will see the destination (not the ID) in the dropdown list.

7. Select both fields with the double arrow that points right and then click Next.

Microsoft Access lesson screenshot 2ndLesson6

The next step in the wizard asks how you would like the records sorted for the dropdown list you are creating. You will sort the records in ascending order based on the destination field (alphabetically), rather than based on the destination’s identification number field (numerically).

8. Click the dropdown list arrow next to sort level 1 and choose Destination. Make sure the sort order is Ascending and then click Next.

Microsoft Access lesson screenshot 2ndLesson7

In the lookup field you are creating, Access will store the ID number for each destination. You will set up the lookup field so that the destination rather than its ID number appears in the dropdown list. Linking to an ID number field ensures that if you change the spelling of a destination in the TblDestinations table, the spelling will also be updated in the dropdown list and in all records of the TblTtrips table where that destination ID was stored.

Instead, you could have created TblDestinations with a single field for the destinations, which would have also served as the primary key. However, if you edit the destinations in the single-field table, the dropdown list should also reflect the changes, but the corresponding records in the TblTrips table will retain the original stored values and will not be updated because there is no unique identification number to serve as a cross-reference.

9. In the next step, leave the Hide key column option selected. Click Next.

Microsoft Access lesson screenshot 2ndLesson8

In the final step, the Lookup Wizard asks what to call this field. You have already named this field, so you keep the default name, DestinationID.

10. When asked what to label the lookup field, make no changes and click Next.

Microsoft Access lesson screenshot 2ndLesson9

11. When asked if you want to save the table, choose Yes.

You may notice that this dialog box informs you that Access will create a relationship between the two tables. This relationship will ensure that database users can only choose a destination in TblTrips from the linked field in the TblDestinations.

Microsoft Access lesson screenshot 2ndLesson10

You are now ready to test the lookup field. When you enter Datasheet View, you should notice the destination field has a dropdown list arrow.

12. Display the Tbltrips table in Datasheet View and verify that the DestinationID field is now a lookup field.

Microsoft Access lesson screenshot 2ndLesson11

As you can see, creating lookup fields makes data entry and editing easier. It also ensures that only data contained in the linked table (destinations in TblDestinations here), can be entered into that field.

Two other fields in this table should also be lookup fields. These are the ClientID and the AgentID fields. In the next few steps, you will turn these fields into lookup fields and link them to the clients and agents tables using the Lookup Wizard.

13. Return to the Design View of TblTrips.

14. In the Data Type column of the ClientID field, click the dropdown list arrow and choose Lookup Wizard.

Microsoft Access lesson screenshot 2ndLesson12

15. When the Lookup Wizard opens, select the option which links to a table or query. Click Next.

16. In the next step, choose the TblClients table and click Next.

Microsoft Access lesson screenshot 2ndLesson13

Here you will select the fields to display in the dropdown list for the ClientID field. You will have Access store the client’s identification number but display the client’s first and last names for easier recognition.

17. Select the ClientID, FirstName, and LastName fields.

You can select an individual field by selecting it in the left column and then clicking the single arrow pointing to the right. You can also double click a field to select it.

Microsoft Access lesson screenshot 2ndLesson14

18. Sort the records by LastName and click Next.

Microsoft Access lesson screenshot 2ndLesson15

19. Leave the Hide key column option selected and click Next.

Microsoft Access lesson screenshot 2ndLesson16

20. Choose the default name for this field and click Finish. Answer “Yes” when Access asks if you want to save the table to create relationships.

Microsoft Access lesson screenshot 2ndLesson17

21. Repeat this process to turn the AgentID field into a lookup field that links to the agents table. Keep the key field hidden.

Microsoft Access lesson screenshot 2ndLesson18

The columns are empty in the dialog box which asks you about lookup field column width (i.e., dialog box with Hide key column box) because you have not yet entered agent data. You will enter records in this table soon.

Table Validation Rules

Field validation rules allow you to specify the information allowed in a specific field. A field validation rule can only check the information entered into one field. There may be times when you want to verify the data in more than one field, such as comparing two dates, or other values. Table validation rules allow you to compare values in more than one field. For example, in the TblTrips table, both the departure date and return date fields will store trip dates. To help ensure that both dates are entered correctly (and not reversed), a simple validation rule might be to require that the return date occurs after the departure date.

In the next steps, you will create a table validation rule which requires that the return date occurs after the departure date.

1. In the Design View of TblTrips, notice if the Properties Sheet task pane appears on the right side of the screen.

Microsoft Access lesson screenshot 2ndLesson19

2. If the task pane is not visible, right-click an empty row in the Description column and select Properties from the shortcut menu.

Access should now display the Property Sheet tab. Notice that the selection type is Table Properties. In this sheet you can set properties for the entire table, as opposed to the individual fields in the Field Properties area.

Under the General properties tab, notice Validation Rule and Validation Text. In the Validation Rule row you can specify the rule or condition for valid data in that field. The validation text is the message that Access displays when improper data is entered.

You will now enter an expression (formula) in the validation rule row to have Access compare the return date and departure date for the record being entered or edited.

Microsoft Access lesson screenshot 2ndLesson20

3. In the Validation Rule row type: [DepartureDate]<[ReturnDate].

When you create expressions, or formulas, field names must be enclosed in brackets, [ ]. If you are typing expressions yourself, you will also want to ensure you spell the field names correctly. You will learn to use the Builder tool that will do some of the typing for you as you continue through this lesson.

Microsoft Access lesson screenshot 2ndLesson21

If you would like a larger viewable area to enter this rule, you can increase the size of the Table Properties task pane by dragging its left edge farther left. Alternatively, you can right click on the Validation Rule row and select Zoom from the shortcut menu. (Shift+F2) is a shortcut key combination for zoom as well.

Microsoft Access lesson screenshot 2ndLesson22

The expression, or formula you entered will cause Access to evaluate these two fields when a record is entered in the table. If the validation rule is not upheld, Access will display the error message contained in the Validation Text row.

4. In the Validation Text row type: There is an error in either the departure or return date.

Microsoft Access lesson screenshot 2ndLesson23

5. Save and close the table.

You should not have any records in the trips table. If you do, an error message may appear when you try to save the table. If this occurs, erase any records in this table and try the save command again.

6. Close any other open tables.

You will enter data into the agents and trips table in a future lesson.

Advertisement

Next step

See the concepts demonstrated.

Continue to Watch for chapter videos and worked examples.

Go to Watch

See it explained

Watch

Choose the explanation or example that best supports your learning.

Next step

Apply what you have learned.

Use the guided questions and activities in Practice.

Go to Practice

Apply what you learned

Practice Lookup Fields and Validation Rules

Use the No Fault Travel database to create three lookup fields and a table-level date validation rule.

Guided Practice

  • Create TblDestinations with the fields and records shown in the lesson.
  • Use the Lookup Wizard to connect DestinationID in TblTrips to TblDestinations.
  • Sort the displayed destinations in ascending order and hide the key column.
  • Create a ClientID lookup that displays ClientID, FirstName, and LastName.
  • Create an AgentID lookup linked to the agents table.
  • Add [DepartureDate]<[ReturnDate] as the table validation rule.
  • Add the specified validation text and test an invalid date combination.

Challenge Yourself

  • Explain which value the user sees and which value Access stores for each lookup field.
  • Create another table validation rule that compares two fields.
  • Test whether the lookup field prevents selecting a key that is not in the source table.
  • Explain the difference between a lookup field and referential integrity.

Check Your Understanding

  • Can you explain why the key column may be hidden but still stored?
  • Can you distinguish a field validation rule from a table validation rule?
  • Can you explain why DepartureDate and ReturnDate must be compared at the table level?
  • Can you identify the source table for each lookup field?

Next step

Save the materials you may need later.

Open Resources for the study sheet, spreadsheets, and related learning materials.

Go to Resources

Keep learning

Resources

Study sheets, downloadable files, companion tools, and related lessons for this chapter.

For educators

Teaching this chapter?

The Instructor tab contains objectives, teaching ideas, assessments, and a printable guide.

Open Instructor Resources

LutherMaddy.com — Helping Humans Learn

Lookup Fields and Validation Rules: Instructor Resources

Teach this lesson

Instructor Resources

Classroom-ready objectives, teaching ideas, questions, and assessment materials for this chapter.

Learning Objectives

  • Create lookup fields from related tables.
  • Choose displayed fields, sort order, and hidden keys.
  • Create lookups for destination, client, and agent keys.
  • Create a table validation rule involving two date fields.
  • Test lookup and validation behavior.

Prerequisite Knowledge

  • Table Design View
  • Relationships
  • Primary and foreign keys
  • Field properties

Teaching Outline

  • Create the destinations table.
  • Use the Lookup Wizard for DestinationID.
  • Repeat for ClientID and AgentID.
  • Review hidden and stored key values.
  • Open the table Properties Sheet.
  • Create and test the date validation rule.

Key Concepts

  • A lookup field can display descriptive information while storing a key.
  • The lookup source can be a table or query.
  • Hiding the key column does not change the stored value.
  • Table validation rules can compare multiple fields in the same record.
  • Validation Text explains why a record is rejected.

Classroom Demonstration

  • Select a displayed destination and inspect the stored DestinationID.
  • Enter a departure date later than the return date and show the validation message.

Questions to Ask

  • Why display names or destinations instead of numeric IDs?
  • How does a lookup field differ from a combo box on a form?
  • Why must the date comparison be a table validation rule?

Teaching Notes

  • Emphasize the difference between displayed and stored values.
  • Verify the Bound Column and source fields after the wizard.
  • Test valid and invalid date combinations.

Assessment Ideas

  • Create all three lookup fields.
  • Create and test the table validation rule.
  • Explain the source and stored value for each lookup.

Grading Rubric

CriterionPoints
Lookup source tables selected correctly2
Displayed fields and sorting correct2
Correct key values stored2
Table validation rule correct2
Validation tested and explained2
Total10

Exam and Discussion Questions

Basic

  • Explain why a lookup may hide a key column while storing that key.

Applied

  • Create a lookup field that displays customer names but stores CustomerID.

Conceptual

  • Explain why comparing two fields requires a table-level validation rule.

Keep Exploring

Continue Learning

Explore step-by-step lessons, interactive calculators, downloadable study sheets, and practical educational resources.