Using Access Databases

advertisement
Access 2007
Using Access
1
Contents
Introduction to Microsoft Access 2007.......................................................................................... 3
Microsoft Access 2007 features
3
Opening a database
4
Database objects
5
Opening objects
6
Working with objects
6
Saving in Access
6
Copying database objects
7
Closing a database
7
Renaming database objects
7
Customising and grouping
8
Data navigation and entry ............................................................................................................. 9
Data navigation
9
Data entry
10
Data selection and editing............................................................................................................ 13
Selecting data in tables
13
Selecting data in forms
13
Editing data
13
Copying and moving data
14
Deleting records
15
Using the undo facility
15
Customising datasheets................................................................................................................ 16
Changing the appearance of a datasheet
16
Re-organising fields
16
More field and row options
17
Adding Totals to a datasheet
18
Sorting records
19
Saving the datasheet layout
21
Finding Records ...........................................................................................................................22
Search
22
Find and Replace
22
Filtering records in a table or form
24
Criteria
26
Exercises
28
Task 1: Data navigation and entry in tables
28
Task 2: Data navigation and entry in forms
28
Task 3: Data selection and editing in tables
29
Task 4: Data selection and editing in forms
29
Task 5: Reorganising data in tables
29
Task 5: Reorganising data in forms
30
Task 6: Locating data in tables
30
Task 7: Locating data in forms
30
Reference list
32
2
Introduction to Microsoft Access 2007
What is a database?
A database is a collection of related data. There are many everyday examples of databases such as: an
address book containing names and addresses of friends and families; a card file holding details of
business contacts; a filing cabinet holding last year’s financial reports. All these are stores for data, or in
other words databases.
What is Microsoft Access?
Access is a software application for managing databases. Access enables you to store, retrieve, organise
and analyse data stored in a database.
Microsoft Access 2007 features
Backstage view (File tab) (Access 2010)
When you first launch the Access 2010 application you are presented with the backstage view. From
here you can perform most of the central operations that affect the whole database such as opening,
closing and saving databases. Recently opened databases appear here. You can access this view at any
time by clicking on the File tab of the Ribbon (see Ribbon and Tabs below).
Ribbon and Tabs
The ribbon is divided into several tabs, some of which are always available and some appear according
to which task you are carrying out. Buttons may be ‘greyed out’ if they are for functions you can’t
perform at that time. The Home tab contains most of the most commonly used features such as the
formatting buttons.
Click on the expand button
to view more options, usually in the form of a dialog box.
Quick Access Toolbar
This is above the ribbon and allows you to perform certain functions quickly. Be default it contains
buttons to save, undo and redo. Click on the drop-down arrow to customise the toolbar by adding
new buttons.
Status bar
The Status bar at the bottom of the screen displays status messages on the left and locking keys on the
right. There are also buttons to change the view of the current object on the far right of the status bar.
3
The Navigation Pane
When you open a database, the Navigation Pane will show you the various objects (tables, queries, forms,
reports, macros and modules) that make up that database. This acts as the control centre for the
database.
Click on the drop-down arrow to group and
filter your objects:
Select Object Type and All Access Objects
to see objects grouped by type and to see all of
them.
Select Object Type and Tables to just see
tables.
Tables and Related views groups objects
according to whether they are linked to a
specific table.
Select Custom to create your own groups (see
Opening a database
Click on the Office button (or Backstage View - File tab in Access 2010) and click on Recent
and open the relevant database if it is a recently opened one or click on Open to browse to the
appropriate database on your drives.
You may see a security message asking you if you wish to Enable Content.
This is because Access believes the database could contain viruses or other malicious content. If you
believe the database to be safe, click on Enable Content to make the database fully available.
You may then be asked if you wanted to make the database Trusted Content. This will mean that you
no longer be asked security questions about this database in future. Use the Help provided for more
information.
4
Database objects
An Access database can be perceived as a file in which different database objects can be stored.
The most fundamental object is the table object: this is where the data is stored in the database. The other
database objects, listed below, are tools that allow the user to manipulate the data held in the table.
A query is a tool that allows the user to request specific data to be gathered from the database.
A form provides the user with an alternative interface for entering, editing and viewing data.
A report is a tool for producing formatted printed output from the database.
A macro is an Object that allows the database to be automated without the need for programming.
A module is an Object that stores Access code written by the user.
In this course we will be looking at the table, query, form and report objects.
Tables, fields and records
A table is a collection of related data.
Tables organise data into columns (called fields) and rows (called records) as shown below. Each record
relates to a single entity (in this example, to a single customer); and each field is used to store a particular
piece of information about that customer (in this example, the company name, contact name etc.).
Fields
Records
Relationships
The tables in a database may be linked to each other by the creation of relationships between specific
fields in the database. These relationships can be viewed in the Relationships window:
Select Relationships on the Database Tools tab
5
Opening objects
Each Object you open in a database appears as a separate window within Access and you can have
multiple objects open at the same time. You can use the Switch Windows button on the Home tab to
arrange the windows in different ways.
To open an Object:
Double click the object in the navigation pane. This opens the object in the view which allows you to
see the data (see below for more details).
Views
Objects can be opened in two or more views. The Design view is used for creating and modifying
objects. The other views vary according to the type of object. All the objects we will be working with
use these other views for viewing data.
Opening an object by double clicking opens them in the default view for navigating, entering or
modifying data. In the case of a table, this is the Datasheet view and in a form, Form view. To open an
object in Design view, right click on the Object and select Design View.
To switch views in an open Object:
Use the View button on the Home tab. Click on the button to toggle between
Design View (left) and Datasheet view (centre) or Form view (right) or use the dropdown arrow for more options.
Working with objects
Access has two different options for working with multiple object windows: Overlapping Windows
and Tabbed Documents. It is recommended that you use the Tabbed Documents option. When you
open additional Objects, these appear as tabs below the ribbon.
Click on an Object’s tab to view it.
Click on the cross on the grey bar to close the current Object.
Helpful hint:
Databases created in Access 2003 or earlier will use Overlapping Windows not Tabbed Documents.
To change to Tabbed Documents:
1. On the File tab, select Options and then Current Database.
2. Under Document Window Options select Tabbed Documents and tick the Display Document tabs
check box. You will need to close and re-open the database to see the changes.
Saving in Access
The Save command is accessed as in other Microsoft Office applications, by using the
button on
the Quick Access Toolbar or pressing Ctrl + S. However, it works slightly differently in Access.
Access automatically saves the data in a record when the focus leaves it. In other words, Access saves a
record’s data when you move to a new record; close the active form, table or database; or exit Access.
6
The Save command does not save data. It is used to save and name new database objects, such as
Tables, Forms and Queries. It is also used to save the design, layout, or structure of a database object
and replace any previous version.
Save As command
These are in the Backstage View, accessed by clicking on the File tab. Save Object As command can
be used to save a copy of the active database object under a different name. The Save Database As
command can be used to make a copy of the current database.
Copying database objects
As well as being able to use the Save As command to create copies of objects, you can also create copies
of objects using the Copy and Paste commands:
1. Right-click on the object you wish to copy.
2. Select Copy from the pop-up menu which appears.
3. Right-click on a blank area of the database window.
4. Select Paste from the menu.
5. Type a name for the copied object and click OK.
Closing a database
It is always good practice to close any objects in a database when you have finished working on them
and before closing the database. Access does not allow more than one database to be open at a time.
To close an object:
Click on the cross in the top right corner of the window.
Closing the database:
Click on the File tab and click on Close database.
Renaming database objects
Database objects can be renamed Navigation Pane:
1. Right-click on the object you wish to copy.
2. Select Rename from the pop-up menu which appears. The object’s name will be selected and
editable.
3. Type the new name for the object.
4. Press the Enter key to confirm the new name.
Helpful hint:
1. An object cannot have the same name as an existing object of the same type.
2. An object cannot be renamed while it is open.
7
Customising and grouping
You can organise different types of Access objects into a Group. For example, you can create a group
for any objects you use to complete a particular set of tasks or that are used by a particular person. You
can also create a group for your ‘favourite’ objects that you use most often.
A Group consists of shortcuts to the database objects that belong to it. Adding an object to a group
does not change that object's original location and all objects of a particular type will still appear when
you click on that object type in the Navigation Pane. For example, when you click on Tables in the
object list, all Tables will be displayed even if they are also part of a group.
Deleting a database object shortcut from a group does not delete the object itself. For example, if you
delete a form shortcut from your group, and then view Forms in the Navigation Pane, that form still
appears in the list of all forms.
To create a group:
1. Click on Custom on the Navigation Pane drop-down menu.
A new group called Custom Group 1 will be created.
2. Right-click on the Group and select Rename to change the name (e.g. Favourites)
3. Drag objects from the Unassigned Objects list onto the name of the Group to add shortcuts to it.
The process above creates groups on the Custom category but you can also rename Custom and create
further categories and then create groups within these categories.
To create additional categories and groups:
Right-click on the top bar of the Navigation Pane and select Navigation Options. From here you can
rename the Custom group, create additional categories and create additional groups within these.
8
Data navigation and entry
Data navigation
This section looks at some of the different ways to navigate through your data. Differences between
form and table navigation will be highlighted in this section.
As you move from record to record in a table, the record selector for the current record and the field
name(s) for the current fields are highlighted in yellow. The specific cells that are selected are shaded in
blue with a yellow highlighted border.
Using Go To
This allows you to move straight to the first, last, next, previous, or a new record.
1. Click on Go To on the Home Tab.
2. Select the option you require from the submenu.
Using the navigation bar
One of the most efficient ways to move between records in large databases is with the navigation
buttons in the lower left-hand corner of the window:
First record
Previous record
Last record
New record
Click here (or press F5) and type the record
number you want and press Enter.
Next record
Using the keyboard
You can use various keys on the keyboard to move around the datasheet or form:
Keys
Table action
Form action
One field at a time:
One field at a time*

Field above
Previous field

Previous field
Previous field

Field to the right
Next field
, Tab,
Next field
Next field
Enter
Next field
-
End
Move to last field in current record.
Home
Move to first field in current record.
Ctrl + End
Move to last field in last record.
Ctrl + Home
Move to first field in first record.
9
Helpful hint:
When viewing a form in Form view, the order of movement between fields is governed by the tab order
which forms part of the Form design.
Navigation and Editing modes
There are two modes available in the Datasheet view, Navigation mode and Editing mode.
Navigation mode
In Navigation mode, the cursor keys on the keyboard will move you from cell to cell, selecting the entire
contents of each cell (see below).
Editing mode
In Editing mode the insertion cursor appears, and the same keys will move you from character to
character within a cell (see below).
When you click with the mouse in a cell you are in Editing mode by default. You can toggle between
the two modes by pressing the F2 key. If you are in Editing mode in a cell you will be returned to
Navigation mode when you leave the cell.
Data entry
This section covers techniques for entering new records in forms and tables.
To follow the steps below, you will first need to open a form in Form view or a table in Datasheet view.
See previous sections for more details.
Adding a new record
Every form or datasheet has a blank record which follows the last existing record. If there are no
records, the blank record is the only record. This blank record is reserved for new data.
There are a number of ways to navigate to the new blank record at the end of your data including:
Click on the New Record button in the Navigation bar (see Record selector symbols below) or
Click on Go To on the Home Tab and select New Record or
Type your data in the first field and press Tab to move to the next field. The record selector symbols
change as you work. (See Record selector symbols below for a key to the symbols).
Repeat the step above until you reach the last field. Pressing Tab from the last field automatically moves
to the first field of the next record and automatically saves the record.
10
Data Entry Tips
AutoNumber field
(contains the word (New) in a new blank record)
Press tab to skip data entry in this field as Access
will automatically create a value in this field.
Check box
Press the space bar to check or uncheck the box.
Enter the current date
CTRL + ; (semi-colon)
Enter the current time
CTRL + SHIFT + ; (semi-colon)
Record selector symbols
Access displays the following symbols in the record selector (the grey area to the left of each record):
Indicates the blank new record
Indicates the current record when it is being edited (changed).
Helpful hint:
Depending on the design of the form, the record selector symbol may not be visible.
Saving a record
As you move from one record to another, the data in the previous record is automatically saved. This
also applies if you leave the record at any time, for example if you use the mouse to click on a nonadjacent record.
Quitting a record without saving
You can use the Esc key to cancel the current entry if problems arise when inputting data, for example
if you receive an error message or make a mistake.
Press once to leave the current field without saving any changes.
Press twice to leave the current record without saving any changes.
Data types
The data you may enter in a specific field will depend on the data types and properties of the field. The
following information covers some of the common restrictions. Access will display an error message
dialog box if you try to break the data entry rules.
Primary key fields
Each record in a database must have a value which is unique to that particular record. This ensures
that the record is uniquely identifiable. For example, if the Employees Table had two employees with first
name John and last name Smith, the Employee ID would act as a unique reference or ID number. This is
known in database terminology as a primary key.
In some cases, this field might be set to be an Autonumber. In this case, Access automatically creates a
number to identify the record, starting from the number ‘1’ and working upwards, never using the same
number twice. When entering a new record, Autonumber fields can be ignored: Access will automatically
create an Autonumber as soon as you begin entering data in the record.
Foreign key fields
These are fields which are linked to a field in another table in order to create a link or relationship to
records in that table. For example, the Orders Table contains a CustomerID Field which must contain a
CustomerID from the Customers Table. This enables us to know which customer has placed the order and
11
what their details are. It many cases, data entry in a Foreign key field is limited to a value in the field it is
related to. In the example above, the CustomerID field in the Orders Table must contain an existing
CustomerID from the Customers Table and no other values may be entered.
Date/time fields
Data entered in these fields should be in a standard date or time format, e.g. 31/10/04 or 16:30. A
calendar icon appears next to date/time fields to allow you to ‘pick’ a date from the calendar.
Drop-down lists
Some fields may be set up as drop-down lists known as combo boxes. In this case, you can select an item
from the list by clicking on the drop-down arrow or you can type in your entry and Access will offer to
complete the entry for you. In some cases the field may be set up to restrict data entry to the dropdown list, in which case you must choose one of the entries on the list.
Required fields
The property for a field may be set to be required, in which case the field cannot be left blank.
12
Data selection and editing
Selecting data in tables
Areas that have been selected are highlighted in yellow. Once an area has been selected it can be edited
or deleted as described in the next sections.
Selecting records
To select a single record click on its Record Selection button (see below)
To select multiple adjacent records, click and drag the pointer down across the record selectors as
required (see below).
To select all records, click on the Table Selector button at the top left corner of the table (see above).
Table selector
button
Record selector
button
Selecting a cell
Position the pointer at the start of the field and, when the pointer is shaped like a white cross, click with
the mouse.
Notice that the complete cell, not just the cell contents, is selected.
Selecting data in forms
Selecting records can be done using the Select drop-down on the Home tab.
To select a record:
From the Select drop-down list choose Select All.
If it is visible, click on the Record Selector button at the left-hand side of the
form (see Record selector symbols section).
To select all records:
From the Select drop-down list choose Select All.
Editing data
This section covers making changes to existing data in a table or form. When completing the following
section, refer to the section on Data navigation, particularly Navigation and Editing modes (page 10).
Part of a field
To replace part of the contents of a field:
1. Navigate to the field using any method.
2. If you are in Navigation mode (i.e. the contents of the field is selected):
Switch to Edit mode by pressing the F2 key.
13
3. Navigate to the part of the cell you wish to modify and modify the data using the keyboard as
detailed below:
Keys to move/edit data within a field in Edit
mode
Delete
Backspace
/
Remove one character to the right.
Remove one character to the left.
Move one character left/right.
Ctrl +
Move one word to the left.
Ctrl +
End
Home
Move one word to the right.
Move to the end of the line.
Move to the beginning of the line.
Entire field
To replace the entire contents of a field:
1. Navigate to the field using any method except the mouse.
The contents of the field will be selected.
2. Type to replace all existing data in the field.
Helpful hint:
If you use the mouse to click in the field, the cursor will be displayed (Edit mode). Press F2 to select the
contents (Navigation mode).
Copying and moving data
Single field or part of a field
You can copy and paste all or part of the contents of a field just as you would in any other Microsoft
Office application:
1. Click and drag the mouse across the text to select all or part of a field.
2. If you are in Navigation mode the entire contents of the field will already be selected.
3. On the Home tab select Copy
to copy data or Cut
to move data.
4. To insert the text, move the cursor to a new position, or to replace existing text, select any text you
wish to replace.
5. On the Home tab select Paste
.
Copying an entire cell
1. Select the entire cell (see Selecting a cell on page 13).
2. Select Copy to copy the cell.
3. Select another cell.
4. Select Paste.
14
Helpful hint:
It is not possible to Cut and Paste an entire cell.
Whole record(s)
You can copy and paste one record or multiple records, either to append as new records in your table
or to replace existing records.
1. Select the required record(s) (see Selecting data in tables section for more details).
2. Select Copy to copy the record(s).
3. To replace existing records, select the records you wish to replace, or to append the record, click on
the New Record selector.
4. Select Paste.
Helpful hint:
When replacing multiple records, there must be the same number of records in the copied selection and the
records being replaced.
Deleting records
1. Select the required records.
2. On the Home tab select Delete or use the Delete key on the keyboard.
3. Click on the Yes button in the dialog box which appears to confirm the deletion.
Helpful hint:
Once you have deleted a record or group of records, you will not be able to retrieve it. For this reason
Access displays a warning message when you delete records.
Using the undo facility
Access provides the facility to undo the last change made to the data. The command may vary
according to the change just made e.g. Undo Typing, Undo Current Field, Undo Current Record, Undo Saved
Record. Note that for some operations (deleting records is one example), the Undo facility is not
available. However Access will warn you if what you are about to do is irreversible.
From the Quick Access Toolbar (top left of the Access window) select Undo
keyboard shortcut CTRL + Z.
15
or use the
Customising datasheets
Changing the appearance of a datasheet
You can change the appearance of a table in Datasheet view to make it easier to read and to distinguish
one table from another. These are available in the Text Formatting part of the Home tab.
Colour alternate rows (select
No colour to use background
colour for all rows)
Click here for more options
Turn gridlines on and off
Re-organising fields
There are a number of ways to reorganise data to make records easier to view. This section covers
customising the layout of a table and sorting records.
You can move fields, adjust field width and row height, and freeze or hide field display in the Datasheet
view. You may also sort the contents of two or more adjacent fields.
Selecting a field or fields
To select a single field (as shown below), click on the Field Selector (the top of the column containing the
heading) .
To select multiple fields, click on the first field’s field selector and, without releasing the mouse button,
drag the pointer across the field selectors of the other fields required.
Helpful hint: only adjacent fields can be selected simultaneously.
Moving fields
1. Select the field or fields you wish to move.
2. Click and drag left or right to the new position.
A bold vertical bar appears to show the position of the field as you drag.
3. Release the mouse button when the vertical bar is in the position you require for the field.
16
More field and row options
You can change the appearance of fields and rows and subdatasheets using the More button on the
Records part of the Home tab.
Changes the row height for
all rows in the table
Change the behaviour of the
subdatasheet
Changing field width or row height
Fit to a specific width/height:
Navigate to any cell in the field or row to be changed or select the fields to be changed.
Click on the More button on the Records part of the Home tab.
Note that changes to row height affect all rows.
Click and drag to new width/height:
1. Position the pointer in the border to the right of the field to be changed (or in the lower border of
the row to change the row height). The pointer changes shape to a double–headed arrow.
2. Click and hold down the left mouse button, drag the pointer to the height or width required and
release the mouse button.
Field width best fit:
1. Position the pointer on the right border of the field heading, as above.
2. Double-click the left mouse button. The width will be set automatically to fit the widest cell entry
currently visible on screen.
Please note, that no best fit method is available for row height.
Freezing and unfreezing fields
In a large table when all fields cannot be viewed on the screen at one time it is possible to freeze fields
so as to prevent them from scrolling off the screen.
Freezing fields
1. Select the fields to be frozen.
2. Click on the More button on the Records part of the Home tab.
3. Select Freeze Fields.
The frozen fields will automatically be moved to the far left of the table.
17
If no fields are selected when you select this command, Access freezes the field containing the insertion
point.
Helpful hint: To move a field which has been frozen it must be unfrozen first.
Unfreezing fields
Click on the More button on the Home tab and select Unfreeze All Fields.
Hiding or showing fields
It is also useful to be able to hide fields, to make it easier to focus on
the fields (fields) of particular interest.
Hiding a field
1. Select the field(s) to be hidden.
2. Click on the More button on the Home tab and select Hide
Fields.
Showing hidden fields
1. Click on the More button and select Unhide Fields.
2. Tick in the fields boxes to be unhidden (displayed) as shown left.
Adding Totals to a datasheet
Totals enable you to count the number of records in a table and perform other aggregate functions such
as finding the sum of values in a column or the minimum, maximum or average value in a column.
To add Totals:
1. Click on the Totals button in the Records group on the Home tab.
A new row will appear below the new record row of your datasheet. The word Total will appear in
the first column in the new row.
2. Use the drop down arrows in the Total row to add specific aggregate functions to a particular field.
The aggregate functions available will depend on the data in the column. For example, columns
containing text can only use a Count function.
The screen capture below shows Totals on the Product table where a count has been added to the
Product Name field and the drop-down options are displayed for the Unit Price field.
18
The Total row is not considered to be one of the records and is therefore not included when records
are sorted.
If you apply a filter to your records, the result of the functions will reflect the filtered data. So, for
example, if you add an Average function to the Unit Price column and then filter products to only
show Beverages then the Total row will display the average price of Beverages only.
Sorting records
Sorting records in a table
In a datasheet you can sort by just one field or by two or more adjacent fields in a single action. Access
always sorts records starting with the left-most field.
1. If necessary move a field or fields so that they are in the correct sort order (left to right).
2. Select the field or fields you wish to sort on.
3. Select either Ascending
or Descending
Example
The example below shows the Customers Table sorted first by Contact Title (Primary Sort) and then by
Company name (Secondary sort) in ascending order. Customers are sorted alphabetically by Contact Title so
that all customers with the same contact title appear together. Within each set of records with the same
contact title, records are sorted by company name.
Helpful hint: The Contact Title field has been moved so that it is to the immediate left of the Company
Name field.
19
20
Sorting records in a Form
In a Form you can sort by one field only:
1. Click in the field you want to sort by in any record.
2. Select either Sort Ascending
or Descending
Saving the datasheet layout
When you close a table you are prompted to save the layout. Saying yes will save any changes using the
features described in this section (Customising datasheets) will be saved for the next time you open the
table.
21
Finding Records
In a small database, data may easily be located by navigation, but in a larger database a search method is
required. Access provides two methods for finding data in Tables and Forms:
Search:
to quickly find a specific string of text
Find:
used to locate a record that matches certain values
Filters:
used to extract temporarily records matching specified criteria
Search
This feature allows you to quickly find specific data.
1. Click in the Search box to the right of the Navigation bar.
2. Type the text you wish to find.
The first instance of this text in the table will be highlighted.
3. Press Enter to move to the next instance.
4. Keep pressing Enter to jump to further instances of the text.
Find and Replace
Locating data using Find
1. Click on the Find
button on the Home tab.
The Find dialog box will be displayed:
2. Type what you are looking for in the Find What box (see below).
3. Click on the Find Next button.
4. Repeat the step above to scroll through all matching records.
Other options in the Find dialog box
Look In: Allows you to specify which part of the database to search (select the field name to search the
field or the table or form name to search all records).
Match: Allows you to specify whether to match Whole Field (the entire contents of the Find What
box must exactly match the entire contents of the field) or Any Part of Field (contents of the Find
What box must exactly match any part of the field) or Start of Field (the contents of the Find What
box must exactly match the beginning of the field).
Match Case: Tick this to find only records where upper and lower case letters match corresponding
letters in your Find What box.
22
Search: Specify whether to search Up (records previous to the current record), Down (records
following the current record) or All.
Replacing field contents
It is possible not only to search for your data but also to replace that data with an alternative. This
allows changes to be made quickly and easily.
1. Click on the Replace button on the Home tab.
The Replace dialog box will be displayed (see below). Notice the similarities with the
Find dialog box.
2. Complete the dialog box as for the Find dialog box (see previous page) to specify the text you wish
to find.
3. Enter the new text (with which to replace the text in the Find What box) in the Replace With
box.
4. To replace specific instances of the search term:
Use the Find Next button to scroll through your records.
For each item you wish to change, click on Replace.
To replace all instances of the search term:
Click on Replace All.
Helpful hint:
Use the Replace All command with extreme caution. You cannot undo the Replace All command.
23
Filtering records in a table or form
Filters and queries are tools that can be used to create a custom view of your data that includes or
excludes records according to specific criteria. A Filter can be used to temporarily change the set of
records you are viewing while a table or form is open. Filters are temporary and are not saved with the
table or form.
Unlike the Find function, which only operates on one criterion, Filters enable you to generate lists of
records based on several criteria in one or several fields.
All the Filter commands are available in the Sort and Filter group on the Home tab.
Filter by selection
This Filter displays only those records that have a specific value in a particular field.
1. Select all or part of the text in a specific cell.
2. Click on the Selection drop-down list. Different options are displayed
depending on what type of data is selected. These options allow you match
or partially match text or match a specific number or date or a range of numbers and dates.
3. Select an option. Only records which meet the criteria you specified will be displayed and all other
records will be hidden.
When records are filtered, a symbol appears indicating which field(s) contains the filter criteria and a
filter symbol and the word ‘Filtered’ appears to the right of the Navigation bar.
Text field example
Select the word Sales in a cell in the Contact Title field of the Customers table and choose Contains
‘Sales’ from the Selection drop-down list. Only records with the word Sales in the Contact Title field
will be displayed.
Date field example
Select a date in the Order Date field in the Orders table and choose On or Before… from the
Selection drop-down list. Orders placed on or before the selected date will be displayed.
Filter by form
Here you enter criteria in the required fields to filter data in several fields.
1. Click on the Advanced drop-down list and select Filter By Form.
2. A datasheet (when filtering a table) or form (when filtering a form) will appear with a Look For tab
at the bottom.
24
3. The filter form will usually display the most recent criteria entered. To ensure that all previous
criteria have been cleared before creating a new filter, select Clear Grid from the Advanced dropdown list.
4. Type any criteria you want to match in the relevant fields. Typing criteria in more than one field
will mean that records will have to match all the criteria you enter.
5. To add alternative criteria that the records could match, click on the Or tab at the bottom of the
form or datasheet. A second form or datasheet will appear for you to enter additional criteria.
6. From the Advanced drop-down list select Apply Filter/Sort or click on the Toggle Filter
button.
The records that match the criteria you have specified will be displayed.
Example
1. Click on object forms and open the form Customers.
2. Select Filter By Form from the Advanced drop-down list.
3. Type ‘Sales Representative’ in the title field and ‘Germany’ in the country field (see the screen capture
above).
4. Click on the Or tab and type ‘UK’ in the country field.
5. Select Apply Filter/Sort from the Advanced drop-down list.
This Filter will display sales representatives from Germany and all customers from the UK.
Helpful hint:
Access automatically places double quote marks “” around criteria in a text field and hash marks ## around
criteria in a date/time field. For more information about using criteria, see Criteria on page 26.
Toggle Filter
Click on the Toggle Filter button to apply/remove the most recent filter criteria you have created.
25
Criteria
Given below are a range of some of the possible criteria that can be used in queries and filters. This is
by no means an exhaustive list – see Access Help for more information.
Note that in certain fields it is only possible to define criteria matching the data type in that field. For
example, it is only possible to specify a particular date or range of dates in a date field and to specify a
particular number or range of numbers in a number field. Access will warn you if you attempt to enter
an inappropriate criterion in a field.
Dates and numbers
To find records matching a specific date or number or a range of dates or numbers:
To find:
Type:
Example
Displays:
Exact match
[date or number]
14/02/03
14/02/03
Greater than
>[date or number]
>100
101 and up
Less than
<[date or number]
<100
up to 99
Greater than or
equal to
>=[date or number]
>=14/02/03
after and including
14/10/03
Less than or
equal to
<=[date or number]
<=100
up to and including 100
Within an
inclusive range
between [date or number]
and [date or number]
Between 1 and 5
1, 2, 3, 4, 5
Text
To find records which contain certain text (a particular word or words or combination of letters).
To find:
Type:
Example
Displays:
Exact match
[text]
Cat
Cat
Text begins with [text]*
[text] followed by any
letters.
Ca*
Cat and Canary
Text occurs anywhere *[text]*
within the field
*Sales*
Assistant Sales Agent,
Sales Manager etc.
Null fields
To find records for which a certain field is blank:
Type ‘Is Null’ in the relevant field.
To find only records for which a certain field contains data (isn’t blank):
Type ‘Is Not Null’ in the relevant fields.
Exclusion
To find fields which don’t match certain criteria add Not to the front of the criteria.
This can be used for text, dates or numbers.
Examples
Not *Manager*:Finds records for which a field doesn’t contain ‘Manager’ anywhere in the field.
Not 14/10/03: Finds records for which a field doesn’t exactly match the date 14/10/03.
Acceptable syntax
Access automatically places double quote marks “” around text and hash # symbols around dates
entered in the criteria line, but numbers are not changed. Access will also add the word “Like” to any
expressions including an asterisk *. To save time when creating queries it is more usual to leave out
these symbols and allow Access to add them.
To ensure that Access recognises dates correctly, they should always be written in an acceptable format.
Access recognises dates in a number of formats but it is recommended to use dd/mm/yy (e.g.
25/12/03) or dd/mm/yyyy (e.g. 25/12/1795) as standard.
Exercises
Task 1: Data navigation and entry in tables
When navigating around the database, use the method indicated in brackets.
1. Open Northwind.mdb.
2. Open the Customers table.
3. Go to the first field in the first record of your table. (using the keyboard.)
What Country does the customer live in?
4. Navigate to a new blank record. (using the navigation bar.)
5. Enter a new record as detailed below:
Customer ID
Company Name
Contact Name
Contact Title
BALGR
Big Al’s Groceries
Al Malone
Owner
Address
City
Region
Postal Code Country
354 Rodeo Dr.
Salt Lake City
UT
12345
Phone
Fax
USA
Task 2: Data navigation and entry in forms
1. Open the Products form.
2. Go to the last record on the form (using the navigation bar.)
What is the Unit Price of this product?
3. Go to a new blank record on the form. (using the navigation bar.)
4. Enter a new record as detailed below:
Product Name
Supplier ID
Category ID
Quantity Per Unit
Gumbo Mix
New Orleans Cajun Delights
Seafood
100 – 200g pkgs
Unit Price
Units In Stock
Units On Order
Reorder Level
Discontinued
50
103
0
100
Yes
5. Go back to the first record on the form (using the keyboard.)
Task 3: Data selection and editing in tables
1. Open the Products table.
2. Go to record number 35 and copy the contents of the cell containing Supplier.
3. Go to the first record and replace the contents of the cell containing Supplier with the copied data.
4. Close the Products table.
5. Open the Order Details table.
6. Select and delete all records with Order ID 10255.
7. Change the contents of the Quantity field in record number 50 to 40.
8. Use the Undo command to restore the original contents of the field.
Task 4: Data selection and editing in forms
1. Open the Suppliers form.
2. Select record number 25.
3. Copy and paste record number 25 as a new record.
Notice the Supplier ID for this new record. Why has it changed?
4. Modify the new record:
Replace the Contact Name with Guy Saint
Modify the Contact Title to Sales Manager.
5. Close the Suppliers form.
Task 5: Reorganising data in tables
1. Open the Suppliers table.
2. Move the Contact Title column so that it is between Company Name and Contact Name fields.
3. Freeze the three columns mentioned above.
Notice what happens to the Supplier ID column.
4. Scroll to the last field in any record to see the result of freezing the columns.
5. Hide the Contact Title and the Supplier ID columns.
6. Close the Suppliers table, saving the changes you have made.
7. Open the Customers table.
8. Change the width of the Contact Name column using the Best Fit method.
9. Sort the table by Contact Title in ascending order.
10. Notice that the Contact Name column is no longer wide enough to display all the data. Use the
mouse to change the width so that all contact names are fully visible.
11. Close the Customers table.
12. Re-open the Suppliers table.
13. Unhide the Contact Title column.
14. Unfreeze the columns.
15. Open the Orders table.
16. Sort the records so that records are sorted by Employee and for each employee are sorted
alphabetically by Customer.
17. Close all open tables.
Task 5: Reorganising data in forms
1. Open the Products form.
2. Sort the products by name.
3. Scroll through the records to view the sorted results.
4. Close the Products form.
Task 6: Locating data in tables
Using filters and sorting:
1. Open the Products table.
2.
Use a filter to display all Beverages with a unit price of more than $18.
Note: do not include the dollar sign [$] in your criteria.
3. Sort the filtered records to check that your filter has worked.
How many records are displayed?
________
4. Modify the filter to show Beverages with a unit price of $18 or less.
How many records are displayed now?
Using Find:
1. Open the Customers table.
2. Find a contact with the surname Camino. What is the record number?
3. Find a customer living in Brazil.
Task 7: Locating data in forms
Using Find and Replace:
1. Open the Customers form.
2. Replace the following:
Find Contacts with Contact Title:
Change their Titles to:
Sales Agent
Sales Associate
Accounting Manager
Accounts Executive (unless they live in Brazil)
Using a filter:
3. Filter the records to display only customers who live in Brazil.
How many are there?
4. Remove the filter.
5. Open the Employees form.
6. Find the record for the employee Michael Suyama.
7. Filter the records to display all employees who have worked at the company longer than Michael.
8. How many staff are there in your result?
9. What criterion did you use to display the records?
Extra Exercise - Revision
1. Open the Northwind database and open the Suppliers table.
2. Move the Country field to the far left of the table (make it the first column). Make the City field the
second field in the table.
3. Search for Ltd in the Company Name field and replace it with plc.
4. Check record 10 and ensure the company name is still Refrescos Americanas LTDA, ie, check
that LTDA has not been changed to PLCA.
5. Apply a filter where the criteria is all the contact names starting with Ch. How many records are
there? Remove the filter.
6. Hide the Phone and Fax fields.
7. Change the row height to 16.
8. Remove the horizontal gridlines.
9. Change the colour of the background and the vertical gridlines.
10. Change the font and change the point size to 12.
11. Apply a filter for all records where the country is USA, listing the result in alphabetical order of
City. Which is the last city?
12. Use Best Fit to set the width of the columns.
13. Change the font to Arial Narrow and point size to 11.
14. Use the Best Fit option again to change the Column Width.
15. Check to ensure the Phone and Fax fields are still hidden.
16. Remove the filter and unhide the phone and fax fields. Close the Table without saving your formats.
17. Open the Orders table.
18. How many records have the employees with surname King and are shipping Via "Speedy
Express"?
19. Remove from the view of the table, all the records where the Ship Country is France, Germany, or
Italy. How many records are left? Remove the filter.
20. List all the records that do not contain a Ship Postal Code. How many are there?
21. Remove the filter and close the table without saving.
Reference list
Using the keyboard
You can use various keys on the keyboard to move around the datasheet or form:
Keys
Table action
Form action
One field at a time:
One field at a time*

Field above
Previous field

Previous field
Previous field

Field to the right
Next field
, Tab,
Next field
Next field
Enter
Next field
-
End
Move to last field in current record.
Home
Move to first field in current record.
Ctrl + End
Move to last field in last record.
Ctrl + Home
Move to first field in first record.
Data Entry Tips
AutoNumber field
(contains the word (New) in a new blank record)
Press tab to skip data entry in this field as Access
will automatically create a value in this field.
Check box
Press the space bar to check or uncheck the box.
Enter the current date
CTRL + ; (semi-colon)
Enter the current time
CTRL + SHIFT + ; (semi-colon)
Criteria
Given below are a range of some of the possible criteria that can be used in queries and filters. This is
by no means an exhaustive list – see Access Help for more information.
Note that in certain fields it is only possible to define criteria matching the data type in that field. For
example, it is only possible to specify a particular date or range of dates in a date field and to specify a
particular number or range of numbers in a number field. Access will warn you if you attempt to enter
an inappropriate criterion in a field.
Dates and numbers
To find records matching a specific date or number or a range of dates or numbers:
To find:
Type:
Example
Displays:
Exact match
[date or number]
14/02/03
14/02/03
Greater than
>[date or number]
>100
101 and up
Less than
<[date or number]
<100
up to 99
Greater than or
equal to
>=[date or number]
>=14/02/03
after and
14/10/03
Less than or
equal to
<=[date or number]
<=100
up to and including 100
Within an
inclusive range
between [date or number] Between 1 and 5
and [date or number]
including
1, 2, 3, 4, 5
Text
To find records which contain certain text (a particular word or words or combination of letters).
To find:
Type:
Example
Displays:
Exact match
[text]
Cat
Cat
Text begins with
[text] followed by any
letters.
[text]*
Ca*
Cat and Canary
*Sales*
Assistant Sales Agent,
Sales Manager etc.
Text occurs anywhere *[text]*
within the field
Null fields
To find records for which a certain field is blank: Type ‘Is Null’ in the relevant field.
To find only records for which a certain field contains data (isn’t blank): Type ‘Is Not Null’ in the
relevant fields.
Exclusion
To find fields which don’t match certain criteria add Not to the front of the criteria.
This can be used for text, dates or numbers.
Examples
Not *Manager*:Finds records for which a field doesn’t contain ‘Manager’ anywhere in the field.
Not 14/10/03: Finds records for which a field doesn’t exactly match the date 14/10/03.
Acceptable syntax
Access automatically places double quote marks “” around text and hash # symbols around dates
entered in the criteria line, but numbers are not changed. Access will also add the word “Like” to any
expressions including an asterisk *. To save time when creating queries it is more usual to leave out
these symbols and allow Access to add them.
To ensure that Access recognises dates correctly, they should always be written in an acceptable format.
Access recognises dates in a number of formats but it is recommended to use dd/mm/yy (e.g.
25/12/03) or dd/mm/yyyy (e.g. 25/12/1795) as standard.
Download