Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 115

Microsoft Access

2007

1
Objectives
• Access or Excel?
• Tables
• Queries
• Relationships
• Forms
• Reports
Access or Excel?
Use Excel when: Use Access when:
 Your data is of a • You are working with
manageable data size large amounts of data
 There is no need for • You need to create
relationships between relationships between
data your data
 You are primarily • You rely on external
creating calculations databases to analyze
and statistics data

3
Working with Multiple Tables –
Table Relationships
Relationship
between two tables

• The strength of Access is the fact that it is a


relational database
– This means you can have multiple tables and create
relationships between each table
– This helps eliminate redundant data
4
Database Objects

Database

Tables Forms Queries Reports

5
Using Microsoft Access 2007
• Access contains four types of components
– Table: used for data storing
– Form: used for data entering
– Query: used for data selection
– Report: used for formally data display
• Basic operations:
– Design tables
– Enter data
– Do queries (select interesting data)
– Produce report
Opening a Database
• Start Access and display the Getting Started
with Microsoft Office Access page
• Click the More option to display the Open
dialog box
• Navigate to the database file you want to
open, and then click the file
• Click the Open button

7
Access 2007 Start Up Screen

Blank Database Table

Table Creation From Online


Templates

8
Create a New Blank Database

9
Access 2007 Interface

10
Save with Quick Access Toolbar

NOTE: To save the database


as you are working, click the
Save button on the Quick
Access Toolbar and enter the
table name, such as
Customer. Then, click OK.

11
Organizing the Shutter Bar

Click the pull-down button in the


Shutter Bar and select  Object
Type to display the objects created
as part of the Customer database
in groups.

Objects that you will create today


include tables, forms, queries, and
reports.

12
Access Objects

• Tables
• Queries
• Reports
• Forms
• Macros
• Modules

Objects
13
Closing and Exiting Microsoft Access
You must perform an appropriate
exit from the database and
Microsoft Access to insure the
stability of the data.

To exit from Access 2007, click


the Office button, and then select
the Close Database option.

Click the Office button again,


and then choose the Exit Access
button.

14
Tables

15
Data Modeling Concepts: Entity
• Entity – a class of persons, places, objects, events, or
concepts about which we need to capture and store
data.
• In database design, it will be converted into a table

• Persons: customer, employee, student.


• Places: building, room, office, campus.
• Objects: book, machine, product.
• Events: application, award, class, flight.
• Concepts: account, bond, course, fund.
Table Design Considerations - Store
Data in its Smallest part
Like this

Not like this

• For greater flexibility, store data in its smallest part


– Instead of one field for an address, use many
– Instead of one field for a name, two or three

17
Table Design Considerations –
Avoid Calculated Fields
• Calculated fields should be used mainly in
queries and reports

Calculated fields in a query

Calculated field in a report

18
Table Design Considerations –
Design Multiple Tables
Multiple tables shown in the Navigation pane

Multiple table tabs identify open tables

• Using multiple tables helps reduce redundancy


– The process is also referred to as normalization

19
Table Structure
• Data is stored in Tables
• Each row is a record (instance)
• Each column is a field

20
Table Structure
A database is made up
• Field of one or more tables
Individual fields
• Record
• Table
• Database

Individual tables in a
database

Records

21
Primary key
• A collection of related tables is called a database, or a
relational database
• You connect the records in the separate tables through
a common field
• A primary key is a field, or a collection of fields, whose
values uniquely identify each record in a table
• When you include the primary key from one table as a
field in a second table to form a relationship between
the two tables, it is called a foreign key in the second
table

22
Creating tables

• Access 2007 includes


two different ways
to create tables.
– Design view
– Datasheet view
• Data can be
imported from Excel
into an Access 2007
table.
23
Work with Table Views
Design View

Datasheet View

• Datasheet View – used to add, modify, delete and


view records
• Design View – used to create and modify the fields in
a table
24
Datasheet View
Primary key field

Navigation buttons Scroll bar


Navigation bar

• Primary Key – a field that identifies each


record as being unique
25
Design View
Key symbol identifies primary key field

• Click F6 to
switch
between the
upper and
lower panes

Set field properties in the


lower pane

26
Creating a Table in Design View
• Click the Create tab on the Ribbon
• In the Tables group, click the Table button
• Right click the table name and open in design
view.
• Add fields and specify primary keys

27
Creating Tables – From the Create
Tab
• Enter table data directly in fields
– From the Create Tab, click Table
• Use a table template
– From the Create Tab, click Table Templates
Enter field names, data
types and descriptions in
Table Design View
Enter data directly into a table,
including the field names

Begin with a template


28
Creating Tables – From the Import
Tab
Click the appropriate application
button
Choose a file type to import

• Click the application from which to import


or
• Choose the type of file you wish to import

29
Create Tables – Specifying field
names Table Design
View
Add field
Table Viewin
Table View

• After choosing your method of creation begin implementing the table design
– Use CamelCase notation for field names
– Specify data types
– Establish a primary key
– Consider the need for a foreign key

30
Create Tables – Primary Key
Primary Key icon
Primary Key Field

• Tables are automatically created with an AutoNumber


field which serves as the primary key
• To change the primary key
– Select a field in Design View
– Click the primary key icon
31
Insert a New Field in the Table

Click the Datasheet tab under Table


Tools, and click the New Field button.

32
FIELD PROPERTIES
• Field Size is used to set the number of characters needed in a
text or number field.
√ save disk space
√ prevent entry errors Likewise, if the field will require more than 50
characters, enter a number up to 255.
• The field size is set in exact characters for Text type, but
options are give for numbers:
– Byte - Positive integers between 0 and 255
– Integer - Positive and negative integers between -32,768 and 32,767
– Long Integer (default) - Larger positive and negative integers between -
2 billion and 2 billion.
– Single - Single-precision floating-point number
– Double - Double-precision floating-point number
– Decimal - Allows for Precision and Scale property control

33
PRIMARY KEY
• Every record in a table must have a primary key that
differentiates it from every other record in the table

• A social security number is an example of a record whose values


will only appear once in a database table.

• Designate the primary key field by right-clicking on the record


and selection Primary Key from the shortcut menu or select Edit|
Primary Key from the menu bar.

• The primary key field will be noted with a key image to the left.
To remove a primary key, repeat one of these steps.
34
PRIMARY KEY
• If none of the existing fields in the table will produce
unique values for every record, a separate field must be
added.

• The field is named "ID" and the data type is


"autonumber". Since this extra field serves no purpose
to you as the user. You may also choose to hide this
column.

35
FIELD PROPERTIES
• Format conforms the data in the field to the same format when
it is entered into the datasheet.

• For text and memo fields, this property has two parts that are
separated by a semicolon. The first part of the property is used
to apply to the field and the second applies to empty fields.

36
TEXT AND MEMO FORMAT
Format Datasheet Display Explanation
 Entry
< HELLO hello < converts characters
to lowercase
> hello HELLO > converts characters
to uppercase

37
DEFAULT VALUE
• There may be cases where the value of a field
will usually be the same for all records. In this
case, a changeable default value can be set to
prevent typing the same thing numerous times.
INDEXES
• Creating indexes allows Access to query and sort
records faster.
• To set an indexed field, select a field that is
commonly searched and change the Indexed
property to Yes (Duplicates OK) if multiple
entries of the same data value are allowed or Yes
(No Duplicates) to prevent duplicates.
VALIDATION RULES
• Validation Rules specify requirements (change word) for the data
entered in the worksheet.

• A customized message can be displayed to the user when data


that violates the rule setting is entered.

• Click the expression builder ("...") button at the end of the


Validation Rule box to write the validation rule.

• Examples of field validation rules include <> 0 to not allow zero


values in the record, and ??? to only all data strings three
characters in length.
VALIDATION RULES
Symbol Explanation
>100 Value has to be greater than 100
<>0 0 value can not be entered
Like “[A-K]*” Value has to start with character A-
K.
Like “A??” Value has to start with A and has to
be 3 letters.
Between 10 and 40 Value has to be between 10 and 40
Between #1/1/98# and Date value must be between
#31/12/98# January 1, 1998 and December 31,
1998.
INPUT MASK
• An input mask controls the value of a record and sets it in a
specific format. They are similar to the Format property, but
instead display the format on the datasheet before the data is
entered.
• For example, a telephone number field can formatted with an
input mask to accept ten digits that are automatically formatted
as "(555) 123-4567". The blank field would look like (___) ___-
____.
• An an input mask to a field by following these steps:
– In design view, place the cursor in the field that the input mask will be
applied to.
– Click in the white space following Input Mask under the General tab.
– Click the "..." button to use the wizard or enter the mask, (@@@) @@@-
@@@@, into the field provided.
INPUT MASK SYMBOLS
Symbol Explanation
A Letter or digit
0 A digit 0 through 9 without a + or - sign and with
blanks displayed as zeros
9 Same as 0 with blanks displayed as spaces
# Same as 9 with +/- signs
?;L Letter A through Z; same as ? but must be entered
C or & Character or space
<;> Convert letters to lower case ; Convert letters to
upper case
PASSWOR Instead of the character “*” is displayed.
D
Entering data
• Use a form, or table view, to enter data.
• Restrict the information that can be entered
in a field.
• Require specific fields.

44
Entering/Deleting/Updating
Record
• Open Table in datasheet view
• Enter new record
– Scroll down to the last record
– Enter a new record
• Delete/update record
– Search the record
– Delete/update

45
Using data types

• You can specify specific parameters for


individual fields:
– What data should be permitted in individual
fields
– Which fields are required
– Which fields, if any, should be indexed
• Begin by using a table’s Design View.

46
Using data types

• Access 2007
supports the use of
numerous field data
types.
• Press the down
arrow in the Data
Type field to display
available options.

47
Data Type
Data type – a property of an attribute that identifies what type of data can
be stored in that attribute.

Representative Logical Data Types for Attributes


Data Type Logical Business Meaning

NUMBER Any number, real or integer.


TEXT A string of characters, inclusive of numbers. When numbers are included in a TEXT
attribute, it means that we do not expect to perform arithmetic or comparisons with
those numbers.
MEMO Same as TEXT but of an indeterminate size. Some business systems require the ability
to attach potentially lengthy notes to a give database record.
DATE Any date in any format.
TIME Any time in any format.
YES/NO An attribute that can assume only one of these two values.
VALUE SET A finite set of values. In most cases, a coding scheme would be established (e.g.,
FR=Freshman, SO=Sophomore, JR=Junior, SR=Senior).
IMAGE Any picture or image.
Selecting/Changing Data Types

On the Datasheet tab, in the


Data Types & Formatting
group, from the Data Type list,
select the desired data type,
such as Number.

49
Work with Table Views

Table View Options

• Click the Home tab


• Click View from the View ribbon
50
Work with Properties
Field Size property

Caption property

• Field Properties can be used to specify


characteristics for individual fields
• Located in the lower pane of Table Design View
51
Indexing

Indexed Property

• Index properties can be set in the Field


Properties pane of table Design View
• Relates the field values to the records that
contain the field value
• Helps speed up some sorting and searching
processes 52
Sorting Table Data

Last Name field Last Name field


sorted ascending sorted descending

• Lists records in ascending or design order


according to one or more fields
53
Forms, Queries, and Reports

54
Forms, Queries, and Reports

Report Query Form

• Forms, queries, and reports are all based upon


data contained in a table
55
Query

56
Queries
• A query is a question you
ask about the data stored
in a database
• Use a Select query to locate
specific records.
• Calculate sums, counts, and
averages using a Select
query.
• Create an Update query to
make mass changes to a
table in one step.
57
Queries
Criterion restricting
dataset to show records
that have a job title of
Sale Representative

Query results showing


only employees who are
Sales Representative

• The answer to the query is a dataset


• The question asked is formed using criteria – the rules or
norm that is the basis for making judgments
58
Using queries
• Access 2007 supports a number of different
query types:
– Simple queries
– Crosstab queries
– Find duplicates
– Find unmatched

59
Using the Query Wizard
• The easiest way to create a new query is by
using the Query Wizard.
• Trigger queries by selecting the Query Wizard
object from the Other section of the Create
tab.

60
Using the Query Wizard
Click the Create tab and select the Query
Wizard button in the Other group.

In the Available Fields list,


double click each field to add it
to the Selected Fields list. (You
can also use the Add, Add All,
Remove and Remove All buttons.)

Use Design View for


entering criteria.
61
Query Design View

In Design View, create specific


criteria for the Query.

62
Creating Criteria and Running a Query
Select the Design/Query
Tools tab in the Results
group, click the Run
button.

Query results can be


reviewed, saved and/or
printed.

63
Select Query

• Searches associated tables and returns a


dataset that matches the query parameters
• Changes made to the dataset will be reflected
in the associated tables
64
Specifying Criteria in a Select
Query
Fields in design grid allow us
to specify criteria for the
dataset

• Field row – displays the field name


• Sort row – enables you to sort the dataset
• Show row – controls whether or not you see a field in the
dataset
• Criteria row – determines the records that will be
selected for display
65
Specifying Criteria – Currency and
Operands
Currency amount entered without dollar sign

Greater than (>) operand


• Specify criteria with currency
– Without the dollar sign
– With or without the decimal point
• Use operands such as:
– Less than and greater than
– Equal to or not equal to

66
Specifying Criteria – Wildcards

Query with question mark and asterisk


Query with asterisk wildcard
wildcard and resulting dataset to specify
and resulting dataset
criteria for the dataset

• Asterisk - searches for a pattern that includes any number of


characters in the position of the asterisk
• Question mark - searches for a pattern that includes a single
character in the position of the question mark
67
Specifying Criteria – Null Values

Is Null criteria and resulting IS NOT NULL criteria and partial


dataset resulting dataset

• IS NULL finds only records that have no value


• IS NOT NULL excludes Null value records

68
Specifying Criteria – And and Or

Or Criterion and resulting And criterion and resulting


dataset dataset

• OR finds records that can match one or more conditions


• AND finds records that must match all criteria specified

69
Copy a Query

• Right click on the query - chose Copy form the


shortcut menu
• Right click and chose paste
• In the Paste as dialog box, give the query a new
name 70
Understand Expressions
• Expressions are formulas based on existing
fields
– Result in a new field called a calculated field
– Used primarily in queries, reports and forms

• Expressions may include


– The names of fields, controls or properties
– Operators like +, *, or ()
– Functions, constants or values

71
What Are Expressions Used For?
• You can use an expression to:
– perform a calculation
– retrieve the value of a field
or control
– supply criteria to a query
– create calculated controls
and fields
– define a grouping level for a
report

Result of a calculation in a report formed by


using an expression
72
Parts of an Expression
Identifiers Value

[Price] * [Quantity_On_Hand] * 0.7

Operator

• Constants: a named item whose value remains constant


while Access is running
• Values: literal values such as the number 1,75 or the word
“Hello”

73
Creating a Calculated Field
Expression using existing fields in a database

Total Value: [Price] * [Quantity_On_Hand]

Descriptive name for new field preceded with colon (:)

 Use correct syntax


 Assign a descriptive name to the field
 Enclose field names in brackets
74
Calculated Field in a Query
Query Design View

Calculated Field

• A calculated field is added to a blank column


in the design grid
75
Saving a Query with a Calculated Field

• Does not change the data in the database


– Only the query structure is saved
– Allows new data to be added to a table that is
associated with a query
• When query executed again, includes the values
of the new table data

76
Expression Builder
• Used to formulate the expressions in a
calculated field

77
Expression Builder

Expand folders
by clicking plus
sign Fields available
in current query

• Use expressions to add, subtract, multiply, and


divide the values in two or more fields/
controls
78
The Expression Builder Work Area

Logical and Work area


operand symbols with
expression

• All expressions begin with an equal sign


• Logic and operand symbols may be either typed or clicked
in the area underneath the work area
• Double-click fields to add them to the work area
79
Access Functions
• Some functions require
arguments
– A value that provides
input to the function
– Separate multiple
arguments with commas

Arguments separated
by commas

80
The IIF Function

The IIF function


syntax in the work
area of the
expression builder

• Evaluates a condition
• Executes one action when the expression
• Alternate action when the condition is false

81
Example of IIF Function
=IIF(Quantity_on_Hand] >= 1, “In Stock”, “Out of Stock”)

Arguments of IIF function separated by commas

• Displays the message “In Stock” if value of 1 or


greater
• Otherwise “Out of Stock” will be displayed
82
RelationShips

83
Using the Relationship Window

Relationship
window
Show Table dialog box

• Add the tables or queries from the Show table


dialog box
84
Establishing Relationships
Click and drag to create a relationship

Primary Key

Foreign Key

• In the Relationship window, click and drag a


field name from one table to a field name in a
related table
85
Referential Integrity

Enforce Referential
Integrity

• Referential integrity ensures that the data in


a relational database maintains consistency
when the data changes
86
Form

87
Forms
Form

First record from table


Underlying table
visible in form

• Forms allow us to create an interface that can be


more user friendly and attractive than Datasheet
View
88
Creating a Simple Form
• A form is an object you use to enter, edit, and
view records in a database
• You can design your own forms, use the Form
Wizard, or use the Form tool to create a
simple form with one mouse click

89
Creating Forms and Split Forms
Click the Create tab and then
select the Form button in the
Forms group.

The resulting form should


appear with the access controls
at the bottom as shown below.

90
Auto Formatting and Saving Forms
Use the Format tab and the AutoFormat
group to select a predefined layout, such as
the “Opulent” layout from the AutoFormat
gallery. The formatted form should display in
Layout View. Save the form to include a
name, such as Customer.

91
Report

92
Reports

Employee Phone Book


table generated as a
report

• Printed documents that display information from the


database
• Allow the layout of data in a useful and attractive manner
93
Planning a Report
• Reports take careful planning in
advance
– Consider information to include
– Decide overall look
– Determine if any grouping levels will
be needed
– What kind of calculations will be
needed
– Determine how the report will be
distributed

94
Identify Data Sources

Determine the
underlying data
source or sources for
your report

• May be based off of one or more tables or


queries
95
Report Tools – Report Tool

Report Tool

Report generated
using the Report Tool

• Generates a basic table based on one table/


query
• Shows all fields in the data source
96
Report Tools – Report Wizard

• Allows use of multiple tables and queries


• All fields in the table do not have to be used
• Capable of summarizing or detailing data
97 97
Report Views – Changing Views

• To change views, click the Views


icon, select the View desired

98
Report Views – Print Preview

Close Print Preview

Print Preview

• Displays the report as it will appear when printed

99 99
Report Views – Design View

• Shows only the structure of the report


• Allows you to customize report elements
100
Report Views – Layout View

• Allows alteration of the report while viewing


the data
• Spacing adjusts automatically
101
Format Report Elements - Property
Sheet
• Accessed by right-
clicking on the report
or an individual
element in a report
• Allows you to change
all available properties
of an element or report

102
Insert Graphical Elements
Select Logo to insert a
new graphical element

• Default graphical element on a basic report is a


report binder logo
• This element can be changed by:
– Selecting the Formatting tab, choose the Logo icon
– Selecting an image from the Insert Picture dialog box

103 103
Divisions of a Report – Detail
Section
Detail Section

• Data repeats once for each record in the


source
104 104
Divisions of a Report – Page and
Report Headers Page Header
Report
Header

• Report headers: printed only once


• Page headers: print at the top of every page
105 105
Divisions of a Report – Group
Headers and Footers

Group Header

Group Footer

• Group Headers appear at the start of a new grouping


• Group Footers appear at the end of a grouping

106 106
Divisions of a Report – Page and
Report Footers

Report Footer
Page Footer
• Page footers: at the end of each page
• Report footers: at the end of the report
107 107
Working with Controls
• Controls allow you to position, display, format
and calculate report date
• Controls are manipulated in Design View
• Two types of controls
– Bound – tied to an underlying source
– Unbound – not tied to an underlying source

108
Using the Report Wizard
• The Report Wizard creates a
report based on answers that
you provide
• Allows application of
predefined styles Click to use the Report Wizard

109
Using the Report Wizard –
Choosing Fields
Choose a field and
click to add
individual fields to Click to add all fields to
the report the report

• Choose or more tables and/or queries for your


report

110 110
Using the Report Wizard –
Grouping Levels
Choose a field to
group by

• Specify primary and secondary grouping


• Change grouping order of precedence
111 111
Using the Report Wizard – Sorting
and Summarizing
Choose one or
more fields to
sort by

Choose the summary value


desired

Clicking the Summary Options buttons brings up the


Summary Options dialog box

• Allows you to specify sorting and summary


options
112 112
Using the Report Wizard - Layout

Choose a layout

• Pick a layout
• Choose landscape or portrait

113 113
Using the Report Wizard –
Choosing a Style
Choose a style

• Choose from several predetermined styles in


this Report Wizard dialog box
114 114
Using the Report Wizard – Naming
your Report
Enter a title fro your
report

• Enter a title for your report


• Choose whether to preview the report or proceed to
modify the design
115 115

You might also like