Filtering
What a filter does
A filter hides records that do not 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, combined with sorting.
- Multiple filters form a chain
If you apply a filter to your datasheet and then apply a new filter, you
will be filtering the already-filtered records. This will likely not give you
the same results as using your new filter by itself! Be sure to remove the
first filter if you want to start over.
- Saving a filter
When you filter a table and then save the table, the last filter you used is
saved with the table. When you open the table again, the filter is not automatically
applied. To apply the last used filter, you must click
the Apply Filter button. You can save a filter as a query to use later.
Example: Filtering Star Wars Collectibles table
in
the starwars.mdb database
The example below 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 criterion.
The results are also sorted on the field
EpisodeID in ascending order and
the layout has been modified by changing column widths and moving some columns.
The Conditionfield is
now in view.

After changing layout and filtering

Original datasheet
How to tell when records are filtered:
-
Navigation bar says so: (Filtered)

- Remove Filter button is displayed on toolbar.
The Remove Filter button's background is orange
when you are use the default WinXP desktop scheme.
- Status bar shows the mode indicator FLTR.

Ways to Filter:
- Filter By Selection
- Filter Excluding Selection
- Filter By Form
- Advanced Filter grid
Filter By Selection
The easiest way to filter is by selection.
- Select a cell with the value that you want see in the results.
- Click on
the Filter By Selection button on the toolbar.
The records that do share the cell's value display; the rest are hidden. Simple!
Filter By Excluding Selection
- Select a cell with the value that you do NOT want to see in the results.
- From the menu select ||.
Your results will show all the records that do
NOT match the cell that you chose.
Filter By Form
When you want to show records based on a combination of criteria, you should
use Filter by Form.
- Click the button
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. "Null" and "Is Not Null"
are the only choices for some data types: memo, hyperlink, Yes/No, or OLE
object.
- Choose the values you want to see in the results. You can make choices
for more than one field. The results must match
all of the choices at once.
- Click
the Apply
Filter button.

At the bottom of the Filter By Form window are two tabs: Look for and Or.
The choices on one tab work as AND. Any result must meet all of the criteria on
that tab. But... you can make other choices on the second tab, which works as
OR. The results must match what you chose on the first tab OR what you chose on
the second tab.
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 this filter.
As soon as you select the second tab, a third one is created. It can get
complicated!
Advanced Filter Grid: Combination Sort and Filter
The Advanced Filter/Sort grid lets you sort and filter on multiple fields.
- From the menu select
| |
A new window appears with a top and bottom pane.
- Existing filter criteria and sorting orders will show in the grid in
the bottom pane.
- Drag any other fields that you want to use for sorting or filtering
from the list in the top down to the grid below.
- Set sorting on a field in the Sort row by choosing "Ascending" or
"Descending" or "(not sorted)" underneath the field name.
- Set criteria in the Criteria rows.
- Enter a value that you want to match in quotes, like "Excellent".
- Enter a values that you do NOT want to see in like NOT "6.99"
- Enter Is Null to find empty values.

Access can
usually figure out what you meant if you do not type the quotes around criteria
values. But, sometimes it gets confused.
Delete a Filter
It is not obvious how to delete a filter once you've created one.
From the menu, |
| . From the
filter's menu, |.
All criteria and sorts are removed. Apply the filter. You
are returned to the datasheet will all records showing. The Apply Filter button
is no longer available, which shows you that the filter is truly gone.
When You Forget What the Filter Does...
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 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
to use Advanced Filter/Sort
|
Start with: Access open but no database open,
mytrips.mdb from previous lesson
Add More Records
It's not much fun to sort and filter with just 3 records. You need to add
some more trips.
- Add the following trip records. (Some fields will be
empty.)
You can type the info in or copy one field at a time and paste directly into
the datasheet.
TripName |
Family Reunion - 2003 |
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 |
TripName |
Hilton Head |
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 |
TravelAgent |
none |
Diary |
Were beach bunnies for 2 days. Played golf and did jet skis. Climbed the
lighthouse. Saw natural history museum. Bought gorgeous shells. |
TripName |
New Orleans Convention |
DateStarted |
May 5, 1995 |
DateEnded |
May 15, 1995 |
Description |
Stayed at New Orleans Hyatt. First 3 days for High Reaches Club. |
Cost |
$2545 |
TravelAgent |
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. |

Now we can try some filtering.
Datasheet: Sort
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.
- Click in the
TripName column somewhere.
- Click on
the Sort Ascending button on the toolbar.
The records rearrange so that the
TripName column is in alphabetical order.
Sorts
are saved: If you save the table at this point, it will be sorted this way when you
open it later.
Experiment - sort each column both ascending and descending.
- Sort the TripID field in ascending order. The records return
to the original display order.
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.
Datasheet: Filter By Selection
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
the Navigation Bar for "(Filtered)", at the Status Bar for
FLTR, or at the
toolbar for
the
Remove Filter button.
- Click in the TravelAgent column in one of the cells with the value
"none".
- Click on
the
Filter By Selection button. Three records match your filter.
Notice that beside the Navigation Bar is the word "(Filtered)".

- Click on
the
Remove Filter button. All records reappear.
Datasheet: Filter By Form: Is Not Null
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.
- Click on the button
Filter By Form.
A one row form appears. It shows criterion for the previous filter,
TravelAgent = "none.
Notice that there are two tabs at the bottom, Look for
and Or. For this section you will work on the
Look for tab.

- Press the DELETE key. "none" vanishes from the form.
-
Click
on the field PhotoLink. A drop list appears. The
actual values in the records do not show, only "Is Null" and "Is Not Null".
This is true for several kinds of fields: memo, hyperlink, Yes/No, or OLE
object.
- Click on "Is Not Null".
- Click on
the
Apply Filter button. Only two records have a link entered.

- Click on
the Remove Filter button. All records reappear.
Datasheet: Filter By Form: Multiple Criteria (AND)
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.
- Click on the button
Filter By Form again.
The previous criterion is still in place: PhotoLink
= "Is Not Null"
- Change PhotoLink to "Is Null".
- In the Cost column, instead of choosing a value, type >1000 .
You now have set 2 criteria for the filter. You are looking for trips that cost
more than $1000 and which do not have a link to photos.

- Click on
the
Apply Filter button. Two records meet the criteria.

- Click on
the Remove Filter button. All records reappear.
Datasheet: Filter By Form: Multiple Criteria (OR)
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.
- Click on the button
Filter By Form again.
- Leave the choices on the tab Look for.
- Click on the Or tab. Another
Or tab appears. No choices have been made on these
tabs yet.
- Select
PhotoLink = Is Null and
TravelAgent = "none"

- Click on
the
Apply Filter button. Four records meet the criteria set on the two tabs:
PhotoLink = Is Null and Cost
> $1000
Or
PhotoLink = Is Null and
TravelAgent = "none"

The trip to Hilton Head shows up even though its Cost
was $1000. Why?
Because it has "none" under TravelAgent.
- Click on
the Remove Filter button. All records reappear.
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 tab.
Datasheet: Advanced Filter/Sort
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.
- From the menu select ||
The grid appears with the criteria and sorting from the last filter
that you applied displayed.

The grid shows only the fields that were used in the last filter and sort
that you applied. The Sort row shows Ascending under the field
TripName. 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.
- Delete all of the fields and criteria by selecting them and
pressing the DELETE key.
- Drag the field name DateStarted from the
list at the top. The mouse pointer changes shape to a rectangle
. Drop it onto the grid in the first column.

- In the Sort row, select Ascending under the field
DateStarted.
-
In
the Criteria row in the first column, type <1/1/1999
-
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#. Cool!
Your filter will look for records with a DateStarted
before January 1, 1999, and will sort them in chronological order.
- Click on
the
Apply Filter button.

- From the menu select again ||
Click
in the second column in the Field row. A down arrow appears in the
cell.
- Click on the arrow to open a list of all of the table's
fields
- Click on Cost.
-
In the Criteria row under Cost, type >=1000
Since both criteria are in the same row, your filter will look for
records that satisfy both: Cost greater than or equal to 1000 and started
before Jan. 1, 1999.
- Click on
the
Apply Filter button.

Remove Filter
- Return to the Advanced Filter/Sort window.
|| .
- From the filter's menu, select
|.
- Click the Apply Filter button.
You are returned to the table, with all records showing and the Apply Filter
button no longer available.
- Close the table. If prompted, choose to save changes.
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.
|