Lecture 5 MS-Access Tables Forms Queries Reports
Lecture 5 MS-Access Tables Forms Queries Reports
Lecture 5 MS-Access Tables Forms Queries Reports
1
Introduction
What’s Access?
Access is a relational database application
designed to handle thousand or a few records
depending upon the user needs
2
Introduction
6
Tables
Design a table:
You can add individual fields to a blank table structure
using the panes in Table Design View
The top pane is the grid and is used to specify a field’s
name, descriptive text, and data type.
The bottom pane is the field properties section and is used to
specify field size and other attributes
Each row in the grid corresponds to one field; a collection
of all fields is grouped into a record
Access denotes that one field in every table contains unique
entries that distinguish that record from others, this is the
primary key field. The primary key field is denoted by a key
symbol in the field’s row selector box to the left of the field
7
row
Tables
Design a table:
Within each field, there are three corresponding
columns in the grid:
The first is the field name column, which defines the name of
the field
The second is the data type column, which regulates what type
of data a field can hold, such as numbers, text, and dates
The third column is the description; information in the
description column appears in the status bar when the field is
selected in either a form or datasheet view
Field names appear as column headers in Table
Datasheet View
8
Tables
Design a table:
A fundamental part of designing an Access database
table is knowing the proper data type to assign to a
field.
9
Tables
Design a table:
Access data types are:
AutoNumber holds records numbering (either incremental
or random)
Date/Time holds dates & times (in a variety of common
formats)
Currency holds currency values
Text holds characters, numbers, punctuation
marks, and special symbols
Memo stores a large quantity of text information
Number holds only numbers, + or – signs, and
decimal places
10
Tables
Design a table:
Access data types (cont.):
Yes/No stores either a Yes or No value; appears in
datasheet view as a checkbox (also called a logical
or Boolean type)
OLE holds graphics, sounds, and other object
Linking & Embedding objects
Hyperlink stores URLs for Internet locations
Lookup creates a field that allows you to retrieve Wizard
value from another table
11
Tables
Enter & delete data:
Creating a database table is a two-part process; the first part
defines the structure of the table. The second part of the
process involves input from the user; this usually demands
physically typing the data into the table
Data can be entered directly into a database table using the
table’s datasheet view; this view displays a table in a grid
format. Each row in the grid is a record, with each cell being
an individual field. You enter data by typing values directly
into these cells
When you advance to a previous or new blank row, Access
writes the data to the table
A single new blank record row will appear at the bottom of the
grid and is denoted by an asterisk (*) in the row selector
12
Tables
Format the datasheet:
You can format the datasheet view to make data entry and
viewing easier and more productive
You can adjust each field (or column width) in the grid to better
view its data. The data may not fully display because the default
column width is too narrow. You can click and drag a grid line
to manually resize a column or modify the column’s properties
Access also enables you to change the text attributes (font size &
style, and color of text) of data appearing in the grid. The
modification of these characteristics is applied to all text in the grid
Changing the column order of fields in the datasheet view will not
modify field order in the actual table structure
Renaming a column header will rename the actual field name
13
Tables
Filter & sort tables:
Records display in the order in which they were created by default
Access provides sorting and filtering features to assist you in
organizing and delineating table data as the number of records
increases
Records can be sorted in either ascending (low to high) or
descending (high to low) order based on a selected field
Filtering data involves specifying conditions that a record must
meet to be selected. Filters can contain single or multiple
conditions (tests) that must be met for a record to be listed. A set of
records produced as a result of a filter is known as a dynaset
You can apply two or more filters to the same table; in such case
logical conditions such as AND or OR are used
When a table is closed, sorted or filtered records return to their
14
original state
Tables
Edit field attributes:
You can make permanent modifications to the
structure of a new or an existing table using design
view. A new table may need modification after initial
data entry has exposed problems. Existing tables
may have to adapt to new data or be modified to
function under different circumstances
Access enables you to change the data type of fields
that already contain values. However, certain changes
don’t provide for successful data conversions, such as
attempting to convert a field full of characters
(text) to a number value
15
Tables
Change format properties:
Access by default displays data in the same format as
it was entered. You can have data displayed in a
different format.
Access allows you to alter the display format but not
the value of data
Located in the field properties pane of table design
view, the format property can access and implement
predefined formats (dependent on data type), or
allow you to construct a custom layout of your own
16
Forms
18
Forms
19
Forms
Use a Form Wizard
The Form Wizard can assist you in constructing basic form
layouts. Instead of constructing a form manually, you can use the
Form Wizard to quickly produce a basic form layout
The Form Wizard prompts you for necessary information to
construct a form according to one of several predefined layout
types. After answering each question, you can advance to the next
window or return to previous windows to select different options
The Form Wizard allows you to define the underlying table(s),
field inclusion, and basic layout schemes. You can quickly create
and link controls to an underlying table(s)
If necessary, you can later customize the form in Form Design
View
20
Forms
Design a Form
Constructing a layout manually allows you to create
more specialized forms
Creating or editing a form manually can be
performed using the Form Design View
There are four design features in the Form Design
View:
Field List Dialog Box: contains a list of fields supported by
the form underlying database table(s). Drag a field to the
form area to instantly create label and text-box controls for
that field
Property Sheet: list properties of the controls on the form and
allows you to modify them
Palette: contains buttons to control the appearance and
colors of forms and objects
Toolbox: contains tools to help you insert controls on the
form layout 21
Forms
Design a Form
The form area (appearing as a grid) can be divided
into several sections
The form supports only a Detail section by default,
which is the main body of the form. Controls linked to
field in this section change every time the form displays
a new record
The Footer and Header sections permit you to create
controls that are not dependent on the current record,
such as title header
22
Queries
Access uses a query to extract information from
a database table. You construct a query using a
design grid
Queries are designed and executed from the
Query window. The window consists of two
panes:
Top pane: displays the field-list boxes and any
relationships or links between tables
Lower pane: contains the design grid and is used to specify
the fields, sort order, and search criteria. Search criteria
must be specified within the column of the field the criteria
will test. Query criteria can be string, numbers or a range
of values 23
Queries
Access displays the results of a query in a layout
called a dynaset, which is a temporary list of
records that match the current query.
Dynasets are linked to the tables used to create
them. If you change the value of a field in a
dynaset, the corresponding field in the underlying
table is changed.
As the data in a dynaset’s base table change, so
does the dynaset
You can save the query and its specifications, but
you cannot directly save a dynaset as a database
24
table
Queries
Sort Data
Access does not sort the records it displays by default.
The records are displayed in the order found
Sorting data presents it in an organized manner.
Sorted results help identify groups and trends
Although Access permits you to use datasheet-
oriented sorted controls, the resulting sort remains only
while the dynaset table is active. If the underlying
query is re-run, the sort order is lost. You can establish a
permanent sort order by specifying it in the design
grid
Each column in the design grid can have a sort order
to be chosen, permitting you to specify a sort order for
one or all fields appearing in the resulting dynaset25
Queries
Sort Data
Complex sorts can be defined by applying sort orders
to multiple fields
Click and drag the column selector of a field (in the
design grid) to reposition the field
The left-most field in the design grid with a sort order
defined will control the primary sort order. If
subsequent fields also have a sort order defined, these
orders will be secondary
26
Queries
Use Multiple Criteria: ANDs / ORs
Single criteria queries are often too limited to extract
specific information. Sophisticated queries use multiple
criteria. Access enables queries to contain multiple criteria
through use of AND and OR conditions
The AND condition is used to join two or more query
criteria. The first criterion and the second one must both test
true before a record is retrieved
AND conditions help construct queries that are restrictive,
reducing the number of records appearing in a dynaset.
When you need queries to be more inclusive, considering one
or more alternative values, OR condition must be used
27
Queries
Use Multiple Criteria: ANDs / ORs
A multiple-criteria query using OR conditions
displays a record if one or the other (or both) of its
criteria tests as true. Records do not display if all the
criteria tests as false
The design grid itself supports AND and OR
conditions. If, however, you need to specify an AND
condition for values in the same field, you must
manually key in the AND operator using the Expression
Builder or Zoom window
28
Queries
Create a Parameter Query
Parameter queries allow you to have Access prompt
you for search values before execution. You can easily
enter different parameter values when prompted,
rather than modifying criteria values in the design grid
for each new search value
Parameter query is useful when you expect to run a
query repeatedly with changes to the query criteria, but
not to the actual structure of the query
Parameter queries can search for different values in
the same fields. This is possible through the
substitution of parameter statements with actual field
criteria 29
Queries
Create a Parameter Query
The text in the parameter statements should be
enclosed in square brackets, and the last character in
the text must be a colon
Example: [Enter City:]
30
Queries
Create a Parameter Query
To prevent you from entering a parameter value that
is of the wrong type (i.e. a string value for a number
field), Access permits you to define data types for the
parameter values. You can define the data type a
parameter will accept in the Query Parameter dialog box,
reducing the possibility of error
Ranges can be used with parameter statements. You
must define the comparison operator before adding the
parameter statement. Access will evaluate the entire
statement as a single expression
31
Reports
A report is a design document that displays
formatted data from one or more database tables.
Reports are designed for printing and
distribution to an audience
Reports are used to summarize large quantities
of data into meaningful information using
calculations, record lists, totals, and other reports
objects
Reports produce paper forms such as invoices
and inventory lists
32
Reports
34