You are on page 1of 37

Topic 4.

Retrieving
Information
MS Access
4.1. Main Operations
• Use the search command for a specific word, number, date
in a field.
• To search for a specific word, number or date in a field you first
need to open the table in datasheet view. Then follow the steps
below:
• Click in the field in which you need to search.
• From the Home tab in the find section click on Find
Prepared by Mr. Patrick Okot
Search …
• In the Find What: field type the word / number / date that you
wish to search for.
• Make sure that the Look In: field is set to your desired field.
• Click on Find Next.

Prepared by Mr. Patrick Okot


Apply a filter to a table, form
• Filters are basically simple queries that only apply to open tables
or forms.
• Filters are best used for temporarily altering the view of the data
in a table: by filtering out records that you don’t want.

Prepared by Mr. Patrick Okot


Apply filters to a table
• Let’s say we need to filter our table so that it only retrieves records
of individuals who reside at Mosta.
• Open your table in datasheet view.
• Click on one of the records that shows ‘Mosta’ as the Town field.
• Click on the Filter by Selection icon from the home tab in the Sort and
filter Section and choose Contains Mosta

Prepared by Mr. Patrick Okot


Filters …

Prepared by Mr. Patrick Okot


Remove the application of a filter from a
table, form
• To remove the filter, click on Filter
icon from the home tab in the Sort
and filter Section and choose clear
filter from locality.

Prepared by Mr. Patrick Okot


4.2. Queries
• A query is used to extract and analyze data.
• As tables grow in size they can have hundreds of thousands of
records, which makes it impossible for the user to pick out
specific records from that table. Queries were designed to
overcome this problem.
• Practically, queries are used to extract and analyze data.
Prepared by Mr. Patrick Okot
Create a named single table query using
specific search criteria
• From the Create tab click on Query Wizard
• Choose Simple Query Wizard

Prepared by Mr. Patrick Okot


• From the Tables/Queries drop down arrow choose the table that
you need
• Then choose the fields

Prepared by Mr. Patrick Okot


• Then click on Next
• Then click on Next again
• Write a title for your query,
choose between open the query
to view information or Modify
the query design and click
Finish.

Prepared by Mr. Patrick Okot


Differences …view / modify
• The difference between open the query to view information or
Modify the query design is that when we need to add some criteria
to the query we use Modify the query design while we use open
the query to view information when there’s nothing else to be
done

Prepared by Mr. Patrick Okot


Create a named two-table query using specific
search criteria
• From the Create tab click on Query
Wizard
• Choose Simple Query Wizard

Prepared by Mr. Patrick Okot


Two tables …
• From the Tables/Queries drop down
arrow choose the table that you need
• Then choose the fields
• Then From the Tables/Queries drop
down arrow choose another table that
you need fields from
• Choose the fields again
• Then click on Next
• Then click on Next again
Prepared by Mr. Patrick Okot
Create …

• Write a title for your query,


choose between open the
query to view information or
Modify the query design and
click Finish.

Prepared by Mr. Patrick Okot


Matching Text
• When you enter text into the criteria cell your text should be
enclosed in quotes ("") to distinguish it from other expressions
and operators that you may need to add.
• To match a word or phrase simply type the text you want to
match. The query will find all the records that match the text
exactly.
• Access will add the quote marks at each end. It is only necessary
to enter the quotes yourself if you type text that might confuse
the query.
Prepared by Mr. Patrick Okot
• For example you may want to type a phrase that contains the
words "and" or "or".
• Access would normally interpret these words as instructions. You
can manually insert the quote marks at each end of the phrase to
make sure the criterion means what you intend it to. This example
will display all the records that contain the entry Mosta in the
Locality field.

Prepared by Mr. Patrick Okot


Add criteria to a query using one or more of the following
operators: = (Equal), <> (Not equal to), < (Less than), <=
(Less than or equal to), > (Greater than), >= (Greater than or
equal to).
• Mathematical operators such as ‘>’ (greater than) or ‘<’ (less than) are
normally used for specifying numbers and dates but can also be used
for text. For example:
• <"N" would find all entries beginning with a letter lower than the
letter N in the alphabet. In other words, all entries starting with the
letters A - M.
• >="F" And <"H" would find all entries beginning with the letters F
and G.
Prepared by Mr. Patrick Okot
Working with Numbers
• When working with numbers we normally use the mathematical
operators to define the range of numbers from which we want to
select. For example, where X represents a number:
• <X finds values less than X.
• >X finds vales greater than X
• >=X finds values greater than or equal to X
• <>X finds vales not equal to X
• It is important that your field type is correctly defined as a
Number field for numerical queries to work properly.
Prepared by Mr. Patrick Okot
Examples …
• To match a number
• Simply type the number that you want the query to find. This example
will display the record(s) with the entry 385 in the Customer Number field.

Prepared by Mr. Patrick Okot


Examples …
• To find values less than a certain number
• Type a less than sign (<) followed by the number. This example will
display all records with an entry less than 1000 in the Customer Number
field.

Prepared by Mr. Patrick Okot


Examples …
• To find values in a range of numbers
• You need to use the expression “Between X and Y”, where X and Y
represent the numbers at opposite ends of the range. This example will
display all records with entries falling within the range 500-700 in the
Customer Number field.

Prepared by Mr. Patrick Okot


Add criteria to a query using one or more of the
following logical operators: AND,
OR, NOT
• When you need to use multiple conditions for a query, you can
use the logical operators to combine conditions.
• The And logical operator specifies that both conditions must be met
• The Or logical operator specifies that one or the other of the conditions
must be met
• When you enter two conditions on the same row of the query design
grid, an And condition is created.
• If you enter two conditions that are on separate rows, an Or condition is
created.
Prepared by Mr. Patrick Okot
Creating And condition in the design grid

• When creating criteria in the same row you are creating an And
condition

Prepared by Mr. Patrick Okot


Creating Or condition in the design grid

• When creating criteria in the separate rows you are creating an OR


condition

Prepared by Mr. Patrick Okot


Use a wildcard in a query, * or %, ? or __
• A wildcard is a special character that can stand for either a single
character or a string of text.
• Wildcards are useful when you want the query to look for a range of
different possible values, and also when you are not certain exactly
what you are looking for but can give the query some clues to work
with.
• The two wildcards we commonly use are the asterisk or star (*) and the
question mark (?).
• 1. The asterisk (*) represents any string of text from nothing up to an entire
paragraph or more.
• 2. The question mark (?) represents a single character only (although you could
use, for example, two question marks to represent two unknown characters).
Prepared by Mr. Patrick Okot
Example
• Yor* would find York, Yorkshire and Yorktown but not New York.
• Mar? would find Mark but not Mario, Martin or Omar.
• F*d would find Fred and Ferdinand but not Frederick.

Prepared by Mr. Patrick Okot


Like "Text*"
• To match text starting with a particular
letter or string, type the letter or string of
text followed by an asterisk.
• Access will add the expression "Like" and
place quotes around your typing. This
example will display all records that have an
entry starting with S in the Company field.

Prepared by Mr. Patrick Okot


Like "*Text"
• To match text ending with a particular
letter or string, type an asterisk followed by
a letter or string of text.
• This example will display all records that
have an entry ending with Plc in the Company
field.

Prepared by Mr. Patrick Okot


Edit a query: add, modify, remove criteria

• To add or modify criteria for a query it’s important that you will
be in the design view of that query.
• Click on the criteria of that particular field and add or change the
criteria as you need.
• To remove the criteria simply place the cursor before the criteria
and press the backspace button till you delete the whole criteria of
that field.
Prepared by Mr. Patrick Okot
Edit a query: add, remove, move, hide,
unhide fields
• To insert additional fields to a query:
• 1. Display the query in Design view.
• 2. In the field list, double-click the field name/s which you want to add.
The Field: (first row), in the design grid, will display the field name
selected. The Table: (second row), in the design grid, will automatically
display the name of the table from which you have selected the field.
• 3. Save the query.
Prepared by Mr. Patrick Okot
To remove fields from a query:
• 1. Display the query in Design view.
• 2. In the design grid, click the small grey cell
above the name of the field to remove. The
entire column will be highlighted.
• 3. Press DELETE key.
• Note that: You cannot undo deletions in
queries in Design view. If you accidentally
delete a field, you will have to add it again to
the query.
Prepared by Mr. Patrick Okot
To move fields within a query:

• 1. Display the query in Design view.


• 2. In the design grid, click the small grey cell above the name of
the field to move. The entire column will be highlighted.
• 3. Drag the column to the location where you wish to place it.

Prepared by Mr. Patrick Okot


To hide field/s from being displayed in the
record set:
• 1. Display the query in Design view.
• 2. In the design grid, deactivate the check box/es in the Show:
cells for the field/s that will not be displayed in the record set.
• In most cases such fields are added to the design grid for criteria
purposes only.

Prepared by Mr. Patrick Okot


To unhide field/s so that these will be
displayed in the record set:
• 1. Display the query in Design view.
• 2. In the design grid, activate (click) the check box/es in the
Show: cells for the field/s that will be displayed in the record set.

Prepared by Mr. Patrick Okot


Run a query
• After having specified the criteria in a query, you have to RUN
the query in order to see the results.
• To run the query press on the Run button in the Design tab in
the Results Section

Prepared by Mr. Patrick Okot


Chapter Exercise

Prepared by Mr. Patrick Okot

You might also like