As you accumulate more records, you will sometimes want to sort the records into a different order or to filter the records to see only the ones that match certain rules, called criteria.
For example, you might want to sort the records by AmountPaid or ItemName or Category.
You might want to filter the records to see only records for the year 2012 or where Cost is more than $500. So many choices!
Star Wars Collectibles table in
the starwars.accdb database
You can download the database to follow along with the illustrations below. If you mess it up, just download again!
Original Datasheet, with no sorting or filtering
Sorting puts the records in order based on the field that you select, either ascending or descending order.
Sort a text field: Alphabetical order.
Ascending: a, b, c... Descending: z, y, x...
Sort a number field: Numerical
order.
Ascending: 1, 2, 3, ..., 100, 101, 102.... Descending: 102, 101, 100, ..., 3, 2, 1
Sort numbers that are in a text field: Alphabetical order like 1, 10, 100, 2, 20, 200... instead of numerical order.
In the context menu, for different data types the symbols are the same but the words for the commands change. This can be more helpful than the fixed text that shows on the ribbon button.
Datasheet sorted on YearMade, smallest to largest
ItemID no longer in numerical order
In one sense, a datasheet is ALWAYS sorted. By default the records show in the order in which they were entered. If there is an AutoNumber primary key field, then that field is in numerical order. An easy way to get back to the original order is to sort on the primary key field, if your table has an AutoNumber primary key.
One sort active at a time
Sorts do not build on each other. A new one replaces the previous one. To sort on
more than one field at once, you must use an advanced filter or a query.
Saved with table
If you save your table while it is sorted, the sorting order is saved.
A filter shows only records that match the criteria that you chose.
A simple filter looks for records that match one value in one field. An advanced filter can have several criteria in multiple fields, and even combine those with sorting.
The symbol for a filter is a funnel,
.
You can save a filter as a query to use later.
In the illustration below the datasheet is filtered to show only items where the Condition field has the value "Excellent". Only 3 of the 14 records in the table match this single criterion.
The results are also sorted on the field EpisodeID in ascending order.
After filtering. Several ways to tell that the datasheet is filtered.
Datasheet Navigation Bar says so: Filtered![]() ![]() 'Filtered' is a toggle button which will reapply the last filter used or remove the filter. That filter is not deleted however. |
Toggle Filter button on the ribbon is highlighted.![]() ![]() |
Status Bar says so: Filtered![]() ![]() ![]() |
Column heading shows Filter icon ![]() ![]() |
The easiest way to filter is by selection.
Button: Click in a cell with the value that you want to see in the results.
Then, click on the Filter By Selection button
on the Home ribbon tab and then on the first item in the list, Equals <what is in the cell>.
Or, click the arrow on the button to open a list of options.
The datasheet refreshes and shows records that match the filter; the other records are hidden. Simple - for a simple filter on one field.
When you want to filter records based on a combination of criteria on two or more fields, you must use a more advanced method. You cannot use this form to sort. The form is just a datasheet with only one row. You can enter criteria for one or many of your fields in this row.
Click on Filter By Form.
A new
window appears with one row, showing each of the fields from the table.
Each field has a drop list of possible values. You can only pick one value for the field. "Null" and "Is Not Null" are the only choices for some data types: memo, hyperlink, Yes/No, or OLE object.
Filter By Form: Filters using a single value for each of two fields
EpisodeID = A New Hope 1977 and
Condition = Good
Filtered datasheet. Only the records that match all criteria on the form's 'Look for' tab.
When you want 'this' OR 'that': At the bottom of the Filter By Form window are two tabs: Look for and Or. The choices on any one tab work as AND so any result must meet all of the criteria on that tab. But... you can make other choices on the second tab, so that the filtered results must match what you chose on the first tab OR what you chose on the second tab. As soon as you select the second tab, a third blank one is created. It can get complicated!
Strange Results: If your results do not show what
you expected, check the form to see if you have choices selected on multiple
tabs or for a field that is out of view. Delete any values that should not be
in the filter.
The Advanced Filter/Sort grid lets you combine sorts and filters and use multiple fields.
The illustration shows a filter that will show any item that is from episode "A New Hope 1997" and is in 'Good' condition OR is from "The Phantom Menace 1999" and was a gift.
Using quotes around values: Access can
usually figure out what you meant if you do not type the quotes around criteria
values and will add them for you. But, sometimes it gets confused. It is a good idea to get into the habit of typing those quotes yourself.
It is not obvious how to completely delete a filter instead of just toggle it off.
Look at the Advanced Filter/Sort. All the sorts and filtering criteria will be there, no matter what method you used to create the filter. This can be very useful! It is very easy to forget what the last filter was. Creating a new filter may just filter the already-filtered results. That's fine if it is what you meant to do. It can be disastrous if you did not realize what had happened.
![]() |
Step-by-Step: Sort & Filter a Table |
![]() |
What you will learn: | to add records to an existing table datasheet to sort a table datasheet on one column to apply Filter By Selection to apply Filter By Form to use Filter By Form with multiple criteria: AND, OR to use Advanced Filter/Sort to remove a filter |
Start with: ,
, Access open but no database open,mytrips-Lastname-Firstname.accdb from previous lesson
It's not much fun to sort and filter with just 3 records. You need to add some more trips.
Back up this database now so you will have a good copy to use if you need to start over. This works well while the database is small.
Access 2007:
> Manage > Back Up Database
Access 2010: File > Save and Publish > Back Up Database > Save As button
Access 2013: File > Save As > Back Up Database > Save As button
Field | Value |
---|---|
TripName | Family Reunion - 2003 |
PhotoLink | |
DateStarted | 5/31/2003 |
DateEnded | 04-Jun-03 |
Description | Drove to Birmingham and stayed at Grandmother's house. Lunch at the park. |
Cost | $250.00 |
Travel Agent | none |
Diary | Arrived just in time for lunch. 50 family members present plus some friends and soon-to-be family members. Played baseball, sort of, after lunch. Unusual "family" rules involving big people running bases for little people or little people running bases for big people. |
Field | Value |
---|---|
TripName | Hilton Head |
PhotoLink | |
DateStarted | 28-Jun-96 |
DateEnded | 06-Jul-96 |
Description | Drove to Hilton Head. Stayed at friend's time share. Beach privileges. |
Cost | $1,000.00 |
Travel Agent | none |
Diary | Were beach bunnies for 2 days. Played golf and did jet skis. Climbed the lighthouse. Saw natural history museum. Bought gorgeous shells. |
Field | Value |
---|---|
TripName | New Orleans Convention |
PhotoLink | |
DateStarted | May 5, 1995 |
DateEnded | May 15, 1995 |
Description | Stayed at New Orleans Hyatt. First 3 days for High Reaches Club. |
Cost | $2545 |
Travel Agent | Through company having the convention |
Diary | Arrived late and luggage not in sight for 2 days. Did get it in time for the banquet. Took special tour of Louisiana plantation homes and the aquarium. Love the jellyfish in black light and the fancy seahorses. |
Datasheet after entering 3 new records.
Now we can try some sorting and filtering.
To start with, records are all listed in the datasheet in the order in which they were added, so the TripID field will be in numerical order. It is an AutoNumber field so it automatically numbers each new record. You can choose to sort on another field.
Sorts
are saved: If you save the table at this point, it will be sorted this way when you
open it later.
Experiment: Sorting
In Datasheet View, each new sort replaces the old one. You cannot use a multiple sort directly in the Datasheet view, like LastName, then FirstName, then MiddleName.
To sort on more than one column at a time, you must use a query or the Advanced Filter
grid, which you will do shortly.
Click the button on the Home ribbon tab:
Access 2007: Clear All Sorts
Access 2010: Remove Sort
Access 2013, 2016: Remove Sort
The records return to the original display order with TripID in numerical order.
Another way to change the datasheet display is to apply a filter. This hides some of the records. Filtering is more fun with more records than you have here!
When are your records filtered?
You must be alert as to whether your datasheet is filtered or not.
Look at:
Navigation Bar
Status Bar
Ribbon
Column Heading
Four ways to know the datasheet is filtered: TravelAgent=none
You can use a filter to check for records that have blank fields, or for records that have values in a particular field. Filter By Form makes either one easy to do.
Notice that there are two tabs at the bottom, Look for and Or. For this section you will work on the Look for tab.
When you want the results to satisfy multiple criteria at the same time, you can use Filter By Form to choose several values on the Look For tab.
When you want to see a combination of results that meet one set of criteria or meet a another set, you can set the different criteria on different tabs.
The results are shown in the original order, not by which set of criteria they met.
The Alaska and New Orleans trips meet the criteria on the Look for tab.
The Family Reunion and Hilton Head trips meet the criteria on the Or tab.
How to know when a filter has
multiple criteria:
Look at the tabs at the bottom of the Filter By Form window. If there are
only two tabs, then all of the criteria are on the Look for tab. If there are more than two tabs, then there are criteria on all but
the last tab. The filtered records must meet the criteria on one of the tabs.
To combine sorting with filtering, you can open an Advanced/Filter Sort grid. This looks a lot like a Query Design View, which you will work with in the next lesson.
The grid includes only the fields that were used in the last filter. There are two criteria rows, which correspond to the two tabs in the Filter By Form from the previous section. This view has an advantage over Filter By Form. You can easily see that there are two sets of criteria involved.
If you had applied a sort, it would show on the Sort line of the grid.
Press the TAB key to move out of the cell in the grid.
Access automatically
revises what you typed to correct format for a date in an
expression: <#1/1/1999# in Access 2007 and 2010 and <#01/01/99# in Access 2013 and 2016. Very helpful!
Your filter will now look for records with a DateStarted before January 1, 1999, and it will sort them in chronological order.
It is easy to toggle a filter off but that does not get rid of the filter entirely. It's still in the background, ready to be used again.
If prompted, choose to save changes.
Alternate method: Click on the title of the table in filter, TripsFilter1. The grid shows in the window. Click on Advance Filter/Sort... and in the menu click on Clear Grid. (You must be viewing the filter grid for this command to be available). No more filter criteria are left, but the Sort choices are still there. Change any sorts to 'not sorted'.
There are more neat things to do with filters, but that's enough for now! Let's move on to another powerful part of a database - Queries.