You finally have two tables that have a relationship. The relationship was created in a previous lesson with the Lookup Wizard (2007) or the Contacts Application Part (2010, 2013, 2016).
Access will recognize matching fields between tables in some cases. In other situations you will have to show Access what fields to match and what kind of relationship it is: One-to-Many, Many-to-Many, or One-to-One.
Examples below are from starwars.accdb .
Access provides a special window for viewing relationships. No tables are shown automatically. You must pick which ones you want to see.
Open the Relationships window: Database Tools > Relationships button
Join lines connect the matching fields between tables. A line with a
1 at one end and the infinity symbol at the
other indicates a One-to-Many relationship for which Access will enforce referential integrity. That means you cannot use a value on the Many side that was not already in the table for the One side.
This is a big help in keeping your data accurate.
On the other side, Access will not let you delete records on the One side that are related to records on the Many side. If you really need to do that, you first have to remove the related records. It would be an unusual situation.
Removing records: Move records to a special storage table instead of deleting them if there is any chance at all that you might need that record later. Only delete records that were faulty to begin with.
Example: In the Star Wars Collectibles database, you want to delete a particular supplier from the table Suppliers. But, Suppliers is on the One side of a One-to-Many relationship with the table Star Wars Collectibles. If that supplier's SupplierID appears in a record in Star Wars Collectibles table, Access will not let you delete a supplier. You must remove the conflict. There are two choices: change the supplier in the records or remove all of the records that used that supplier. Only then you can delete the supplier. Be careful and thoughtful before making changes like this to records. Tossing data out can often cause trouble later on when you find that you needed that data after all.
The Relationship window has its own ribbon tab.
Edit Relationships opens a dialog about the selected relationship. So you should click on a join line before clicking this button.
Clear Layout removes all of the tables from the window, but no relationships are actually deleted.
Relationship Report creates a printable version of the layout in the Relationship window. If a table has a scroll bar, then the fields out of sight will not print. Resize the display of the table first, then create the report.
Show Table opens a dialog that lists all of your tables and queries. You can show any or all of them in the Relationships window.
Hide Table removes the current table only from the layout and does not change any relationships.
Direct Relationships shows the relationships to a selected table. A table that you hid in the Navigation Pane will not show here either.
All Relationships shows all tables and all relationships, except those tables that you hid in the Navigation Pane.
![]() |
Step-by-Step: Table Relationships |
![]() |
What you will learn: | to view a relationship between two tables to delete a relationship to create a relationship between two tables to print relationship report to edit a subdatasheet to see referential integrity in action |
Start with: mytrips-Lastname-Firstname.accdb from previous lesson
There is a special window for viewing Relationships. Let's look at the relationship you created in a previous lesson.
On the Database Tools ribbon tab, click onthe button Relationships
.
The Relationships window opens. It may be blank or it may show
existing relationships created by the Lookup Wizard or an Application Part.
If the window is blank, you can tell Access which tables to display in the Relationships window.
For practice, let's look at how to create a relationship.
If the window is not empty, click on the Trips table in the
Relationships window and press the Delete key.
That table vanishes along with its join line.
Changing Relationships window: When you delete a table in the Relationships window, you have changed only what is shown in
the window. No properties are changed; no relationships are broken.
Select the table Contacts and click the Add button.
The Relationship window now shows a list of all the
fields in the Contacts table.
The default size of the list is too short to show all fields, so a scroll bar appears.
If necessary, drag the Show Table dialog to a position where you
can see the list in the Relationships window.
Close the Show Table dialog by clicking the Close button.
A line
that connects the two tables because they already have a relationship - the Lookup field.
The fields in the Trips table are in a different order in Access 2007.
Matching Data Type: Fields
must have the same data type to be used to create a relationship between
tables. Usually primary key fields are used to create the relationship.
Names for Joined Fields: The names are often the same but it is not required that they be identical. In this lesson you are joining ID and Travel Agent. It is more common to use identical names.
Access will now remember which tables were showing and their sizes and arrangement in the window for the next time you view Relationships.
Why would you want to delete a relationship? If you need to make changes to the table design, Access may not let you while there is a relationship to another table. Of course, you need to be careful that the relationship will still work after you make your changes!
You will delete the relationship for practice and so you can recreate it manually.
Click Yes.
The line vanishes but the tables are still displayed.
To create a relationship manually is a simple drag and drop action. You will create a new join between the two tables, but it will not be quite like the earlier one.
So far you have only used a relationship as part of a Lookup field. But, the join type affects any queries that use both tables.
Missing Results: If a query leaves out records that you expected or includes extra records that you did not want, the cause may be the join type. Happily, you can make a temporary adjustment in the Query Design View, instead having to change the join in the Relationships window.
Drag the field ID from the Contacts table and drop it on the Travel Agent field in the Trips table.
(Be careful to drop on the correct field!)
The Edit Relationships dialog appears, showing the table names and the field
names for the relationship.
Verify the table names, field names, and relationship type (at the bottom of the dialog): Relationship Type: One-to-Many.
Access figured out the type of relationship automatically. In the dialog, the table on the left (Contacts) is the One side; the table on the right
(Trips) is the Many side. One travel agent in Contacts can have many trips. So the same ID could show up in many records in the Trips table.
Problem: Your dialog does not match the illustration.
You have dragged the wrong field or dropped onto the wrong field. You might see a Relationship type like One-to-One or Indeterminate.
Solution:
Click on Cancel and try again.
Click the button Join Type...
The Join Properties dialog appears.
There are three choices, which determine how records will be matched up in a query. You have not yet worked with a query that used two or more tables.
Query Design and Relationships: In the Design View for a query, you can add, delete, or modify relationships but those changes affect only the query results. When a query seems to be leaving out some of the expected results, look at the relationships. Maybe you need to modify the join type.
Click on the Save button on the Quick Access Toolbar to save this layout.
Access will remember which tables are showing, the sizes of the tables, and their placement in the window.
There is no print button in the ribbon tab for Relationship Tools: Design but there is a special button to create a printable report of the Relationships layout. What you see on screen is close to what you get in the report. If some fields are out of sight in the table's field list, they won't print either. You should arrange the layout before creating the report.
On the ribbon tab Relationship Tools: Design, click the button Relationship Report .
Access creates a report and shows it in Print Preview.
The report shows the tables and joins that are in the Relationships window. It seems to pick up one or two fields that are not showing on the screen but it does NOT automatically show all fields.
The report includes the database name, which includes your name. The dark blue section holds the table name.
As you saw in a previous lesson, a table that is in a One-to-Many or One-to-One relationship can show a subdatasheet of the related records from the other table. You can actually edit the records in the subdatasheet.
Open the Contacts table.
How
to see or hide all subdatasheets at once:
Method 1: Button menu
On the Home ribbon tab, click the More button and then hover over Subdatasheet to expand the menu.
Choices are Subdatasheet..., Remove, Expand All, and Collapse All. Most items will
not be available if the focus is in a subdatasheet.
Method 2: Select whole datasheet first
Select all records by dragging or click the Select Table button at the top left of the datasheet. Click an Expand button
or a Collapse button
and the action you chose is applied to all subdatasheets at once.
Let's see what Access will do now that it must enforce referential integrity
on your new join.
[Be SURE the join between your two tables is still there and still has the box checked for Enforce Referential Integrity!]
Press the Delete key to delete the record.
A message appears. Access will not let you delete the record because it is
related to records in the Trips table.
Changing a related record: You can change anything about a record that is related to records in another
table, like Hector Chavez, except the field that is shared. In
this exercise the shared field was an AutoNumber field, which you cannot
change anyway!
Deleting an unrelated record
from a related table: Access will allow you to delete a record in a table
that has a relationship as long as that particular record is not referred to
by another table. For example, Sheila Landers could be deleted from Contacts because no trips show her as the travel agent.