Professional Documents
Culture Documents
Access 2007 Notes All Chapters PDF
Access 2007 Notes All Chapters PDF
Table of Contents
Chapter 1 ............................................................................................................................................. 1
Introduction to MS-Access 2007......................................................................................................... 1
1.1. MS-Access 2007: ................................................................................... 1
1.2.
1.3.
Database ..................................................................................................... 3
Table ................................................................................................ 7
2.3.
2.4.
2.5.
2.6.
2.7.
2.8.
2.9.
3.3.
3.4.
3.5.
3.6.
3.7.
Append Query:........................................................................................................ 55
3.8.
3.9.
SETEC University
Chapter 4 ........................................................................................................................................... 71
Creating and Using Form .................................................................................................................. 71
4.1. Form Form tool: .................................................................................... 71
4.2.
View form:.............................................................................................................. 72
4.3.
4.4.
4.5.
4.6.
4.7.
4.8.
form : .......................................................................................................... 82
II
5.2.
5.3.
5.4.
5.5.
5.6.
5.7.
5.8.
Table of Contents
SETEC University
Chapter 1
Introduction to MS-Access 2007
Introduction
Microsoft Access 2007
Computer Application
desktop computer
computer network
MS-Access 2007
-
Table:
Query:
Form:
Report:
(Store)
Tables
Table
1.1.
MS-Access 2007:
-
Access 2007
-
:
File
Double Click
Start Run
Open:
msaccess
Enter
OK
Page 1 of 140
SETEC University
MS-Access 2007
Title bar:
Button
Office
Quick Access Toolbar
Title bar
Customized Button
Office Button
Office Button:
Button
(Save)
Database
-
Redo
Icons
Customized Button
Quick Access
Icons
Page 2 of 140
SETEC University
MS-Access 2007
:
: Template Categories:
(Categori s
(Template)
:
-
Database
:
1.2.
Database
Microsoft
Databases
MS-Access 2007
-
Office Button
:
:
1.3.
Close Button
Exit Access
Title bar
Alt + F4
Datab s
Office Button
:
(Template Categories)
Featuring
-
Blank Database
File Name:
New
Database
Folder
Save as type
Create
Page 3 of 140
Program Window
SETEC University
MS-Access 2007
Ribbon
Tabbed Documents
Navigation Pane
View Button
Status bar
-
The Ribbon:
Program Window
Commands
Navigation Pane:
objects
Database
-
Tabbed Documents:
Macro
Tab
Page 4 of 140
SETEC University
Status bar:
Program Window
Buttons
1.4.
View
Databas
-
Browse
Database Double-Click
Database
Open
Page 5 of 140
SETEC University
Chapter 2
Creating and Using Table
Table?
Table
object
MS-Access
2.1.
T
1.
Database
2.
Program Window
Field/Column Headers
Row/Record
Headers
Tabbed document
3.
4.
Field/Column Headers
Column
Field
5.
Page 6 of 140
Save
Field/Column Headers
Rename column
Tab
Enter
Table
OK
Chapter 2: Creating and Using Table
SETEC University
2.2.
1.
Ribbon,
Create
2.
3.
Icon: Table
Field/Column Headers
Column
Field
4.
Save
2.3.
T
1.
Ribbon,
Field/Column Headers
Rename column
Tab
Enter
Table
OK
Table Templates
Create
Templates
2.
Save
2.4.
Fi l
Table
olumn
OK
Table
:
1.
Table
2. Right-click
3.
Datasheet View
Field/Column Header
Column
Insert Column
:
1.
2.
Field/Column Header
Ribbon,
2.5.
Fi l
Column
Datasheet
olumn
Icon: Insert
Field
Templates
1.
2.
Table
Datasheet View
Field/Column Header
Column
Page 7 of 140
3.
Ribbon,
4.
Field Templates,
SETEC University
Datasheet
Fields
Table
2.6.
Fi l
1.
Table
2.
olumn
Datasheet View:
Datasheet View
Field/Column Header
Column
3.
Ribbon,
Datasheet
Field List,
Fields
Table
2.7.
Fi l
olumn
Datasheet View
:
1.
Table
2. Right-click
3.
Datasheet View
Field/Column Header
Field
Delete Column
YES
:
1.
2.
3.
Table
Datasheet View
Field/Column Header
Ribbon,
Field
Datasheet
Icon: Delete
YES
Page 8 of 140
SETEC University
2.8.
T
1.
Design View
Ribbon,
Create
2. Field Name:
Field
3. Data Type:
user
Text:
Memo:
Field
Table
Number:
Date/Time:
Currency:
Page 9 of 140
SETEC University
AutoNumber:
user
record
-
Yes/No:
user
(Yes/No,
True/False, or On/Off)
-
(Files)
sound
-
Hyperlink:
Web Page
Text
(Path/URL)
Website
Attachment:
(attach)
Lookup Wizard:
List
Table
4. Description:
5. Field Properties:
Page 10 of 140
File,
Field
Database
user
List box
Combo box
Field
Status bar
Fields
SETEC University
Field Properties
Data Type
Text
Data Type
Field Properties
Field Size:
Format:
user
Field
Datasheet View
>:
<:
@[color]:
E.g :
@[red]/[black]/[blue]/[green]/[cyan]/[magenta]/[yellow]/[white]
-
Input Mask:
:
+ -
0 (zero):
9 (nine):
+
-
+
#:
-
: Space
user
L:
? (Question mark):
A:
a:
&:
sp
C:
sp
<:
>:
- Caption:
Label
Column Heading
Datasheet view
- Validation Rule:
- Validation Text:
user
Form
Field
Text
Message box
Validation Rule
Page 11 of 140
Data Type
SETEC University
Field Properties
- Required: - o
Field
- Yes:
-
Field
String
Null string
String
Null string
- Indexed:
- No: The field is not indexed (default).
Number
index
- Yes(Duplicates OK):
index
Field
user
- Yes(No Duplicates):
index
Field
user
Field
- Field Size:
-
- Format:
Date/Time
Page 12 of 140
- Format:
-
SETEC University
Data Type
Field Properties
-
ddd: Display the first three letters of the day of the week.
- Input Mask:
-
Date: 00/00/00
Time: 00:00:00
E.g. 1 :
Input mask
Sample values
(000) 000-0000
(206) 555-0248
(999) 999-9999
(206) 555-0248
( ) 555-0248
(000) AAA-AAAA
(206) 555-TELE
#999
-20
2000
>L????L?000L0
Chapter 2: Creating and Using Table
SETEC University
>L0L 0L0
T2F 8M4
00000-9999
9811598115-3007
>L<??????????????
Maria
Brendan
SSN 000-00-0000
SSN 555-55-5555
>LL00000-0000
DB51392-0493
E.g. 2:
ValidationRule Property
ValidationText Property
<> 0
Lik A????"
Field
(Records)
Table
Field
1.
Table
Primary Key:
Design View
Field
Primary
Key
2.
Ribbon,
Tab: Design
Primary Key
1.
Table
2.
Ribbon,
Design View
Tab: Design
Field
Primary Key
2.10.Import Table:
Import Table
1.
Page 14 of 140
Database
Database
Import Table
SETEC University
2.
Ribbon,
Window
3.
4.
Browse
Database
Import T
l s, qu ri s, forms,
Window
Tables
OK
Page 15 of 140
5.
Import O j
SETEC University
t,
tab: Tables
Import
6.
1.
2.
OK
S v import st ps
Import Table
File
Excel
Page 16 of 140
Close
MS-Excel
Database
Ribbon,
Tables
Import Table
t
Ext rn l D t Import:
Window
SETEC University
Browse
3.
File MS-Excel
Import th sour
sh
Tables
t Wiz r
OK
:
Page 17 of 140
4.
Show Worksh
Import
Page 18 of 140
SETEC University
ts
Next
List
window
sheet
:
SETEC University
5.
First Row
Column heading
6.
ont ins
olumn H
Next
Field
ing
window
row
:
Field Name:
Field
Data Type:
Indexed:
Index
Do not import fi l
Skip
Import
Field
7.
Next
window
Page 19 of 140
8.
SETEC University
:
Let Access add primary key:
Access
Page 20 of 140
Next
primary key
Field
primary key
primary key
window
SETEC University
10.
Table
11.
Import
Import to T
Finish
Close
1.
Export table
File MS-Excel:
Navigation bar,
table
Export
2.
Ribbon,
Ext rn l D t Export:
Excel
Window
Page 21 of 140
3.
SETEC University
Browse
options
Export table
layout
export
OK
2.12.
file
records
Close
Link
1.
2.
Table
Database
Database
Ribbon,
Import,
Page 22 of 140
Link table
tab: External Data
Icon: Access
Window
SETEC University
3.
Browse
4.
Database
Link to th
Window
5.
t sour
Link tables
OK
Link T
l s,
Tables
Link
OK
Chapter 2: Creating and Using Table
Page 23 of 140
2.13.
SETEC University
Lookup Wizard
Lookup Wizard
1.
table
2.
Design View
Data type: Lookup Wizard
Field
Lookup
3.
Page 24 of 140
SETEC University
4.
I will typ in th v lu s th t I w nt
window
Number of columns:
5.
6.
columns
Col1,
Next
7.
Next
window
lookup column
Finish
8. Save table
Page 25 of 140
SETEC University
Lookup Wizard
1.
table
2.
Tables/Queries
Design View
Data type: Lookup Wizard
Wizard
3.
Field
Page 26 of 140
Lookup
:
l or
Next
SETEC University
4.
table
column
5.
query
Next
Fields
Av il
l Fi l s
Lookup column
6.
Lookup
Field
Next
Fields
Next
Page 27 of 140
7.
SETEC University
column
mouse
Hi
(drag)
k y olumn r
omm n
column
key column
8.
Next
9.
10.
lookup column
+ Yes:
+ No:
Page 28 of 140
save table
Finish
relationships
relationships
Chapter 2: Creating and Using Table
SETEC University
lookup column
1.
table
2.
Field
Design View
Field Properties,
ontrol,
Field
tab: Lookup
lookup column
Displ y
Text Box
3. Save table
Page 29 of 140
SETEC University
2.14. Relationships:
Relationships:
1.
Ribbon,
Show/Hide,
2.
tab: Design
: Right-click
Relationship Window
Show T
Page 30 of 140
Show Tables
:
SETEC University
3.
tab: Tables
tables
relationship
Add
4.
Close
5.
Primary key
Relationships
(drag)
Foreign key
Edit
Page 31 of 140
6.
SETEC University
Create
7.
tab: Design
Relationship:
1.
tab: Design
Icon: Close
Relationship tab
Icon: Relationship
Relationship tie
2. Double-click
: Right-click
Page 32 of 140
Relationship tie
Relationship tie
E it R l tionship
SETEC University
3.
Relationship
Tables
rim ry
Foreign Key
Foreign table
4.
1.
2.
OK
Relationship:
tab: Design
Icon: Relationship
Relationship tie
: Right-click
3.
2.15.
key: Delete
Relationship tie
Delete
Yes
Password:
1.
Password
database
Database:
Exclusive Mode:
Page 33 of 140
Office Button
SETEC University
Open
Database
Password
Open
button:
Op n
Ex lusiv
Page 34 of 140
SETEC University
2.
Ribbon,
Database Tools,
Icon:
Password:
Password:
Verify:
4.
1.
2.
Password
Password
OK
Password
database
Ribbon,
Exclusive Mode
tab: Database Tools
Database Tools,
3.
Database
Password
OK
Page 35 of 140
SETEC University
Chapter 3
Creating and Using Query
I.
Query?:
Query
object
MS-Access
table
tables
Query
Query
Form, Report
Access Page
Query
Data
MS-Access
1. Select
Query:
u ry
table
Select Query
: Sum, Count, Average, Max
2. Action Query:
Query
in
l s
Action Query
Delete Query :
Update Query :
table
table
Append Query :
table
table
Make-table Query:
table
3. Parameter Query:
Query
4. Crosstab Query:
Query
Page 36 of 140
sum,
average,
SETEC University
ount,
query
SQL Statement
UPDATE
ORDER
SQL
relational databases
Microsoft Access
II.
Query:
3.1.
1.
S l
Ribbon,
u ry
tab: Create
Wizard
2.
wizard:
Win ow
Simpl
Other,
w
u ry Wiz r
Icon: Query
u ry
OK
Page 37 of 140
3.
T
List Av il
l s
u ri s,
Table
l Fi l s,
List S l
4.
SETEC University
Fields
t
Query
Fi l s
Next
5.
Page 38 of 140
D t il shows v ry fi l of v ry r
or
Next
SETEC University
6.
query
Op n th qu ry to vi w inform tion
Finish
Lab 1: Create select query by using wizard:
1.
2.
s orthwin .
Select Query
table Products
: ProductID, ProductName,
UnitPrice, UnitsInStock.
3. Save query
qry ro u ts
Lab 2: Create select query by using wizard: (Modify the query design)
1.
2.
s orthwin .
Select Query
table Customers
: CustomerID, ContactName,
t n
hoos o ify th qu ry
sign
Run query:
Ribbon,
Result,
Icon: Run
Page 39 of 140
3.3.
S l
1.
u ry
Ribbon,
2.
Design View:.
tab: Create
Design
Add
3. Double-click
:
Fi l
Other,
Win ow Show T
tab: Tables
SETEC University
Icon: Query
l
Tables
Close
Query Window
Field
mouse
Field
(drag)
table
Page 40 of 140
tables
Chapter 3: Creating and Using Query
SETEC University
Sort
Show
Criteria:
(Ascending/Descending).
: >,
(wildcards)
h r
t r
E.g. Lik sm iy th
E.g. Lik sm i th
E.g. Lik -
uncheck
u ry D sign,
Page 41 of 140
Lab:
Select Query
1.
SETEC University
Design View:
database: Northwind.accdb
2.
Select Query
table: Customers
a.
b.
London
c.
3.
Fr
Select query
table Products
a.
b.
t goryID=8 S
foo
c.
Chang
Unit ri
$18.00
4.
Select query
table Orders
a.
12/11/1996
20/04/1997
ShipCountry=Germany
b.
(ShipRegion)
c.
5.
WA, CA, SP
(ShipRegion)
Select query
ustom rs
Orders
Homework
1.
ProductName, UnitPrice
(Categories)
2.
Seafood
ProductName, UnitPrice
3.
CategoryName
CategoryName
(Categories)
Seafood
UnitsInStock
E.g: Norwood, Carnarvon,
Sir Ro n y,
Page 42 of 140
SETEC University
E.g:
> 234
Returns all numbers greater than 234. To find all numbers less
than 234, use < 234.
>= "Cajhen"
Returns all records from Cajhen through the end of the alphabet
Between #2/2/2007#
And #12/1/2007#
Not "Germany"
Finds all records where the exact contents of the field are not
exactly equal to "Germany." The criterion will return records that
contain characters in addition to "Germany," such as "Germany
(euro)" or "Europe (Germany)".
Not "T*"
Not "*t"
Finds all records that do not end with t. If your database uses the
ANSI-92 wildcard character set, use the percent sign (%) instead
of the asterisk (*).
In(Canada,UK)
Like "[A-D]*"
In a Text field, finds all records that start with the letters A through
D. If your database uses the ANSI-92 wildcard character set, use
the percent sign (%) instead of the asterisk (*).
Like "*ar*"
Finds all records that include the letter sequence "ar". If your
database uses the ANSI-92 wildcard character set, use the
percent sign (%) instead of the asterisk (*).
Page 43 of 140
Lik
ison
SETEC University
Finds all records that begin with "Maison" and contain a 5-letter
Dewe?"
second string in which the first 4 letters are "Dewe" and the last
letter is unknown. If your database uses the ANSI-92 wildcard
character set, use the underscore (_) instead of the question mark
(?).
#2/2/2007#
Finds all records for February 2, 2007. If your database uses the
ANSI-92 wildcard character set, surround the date with single
quotation marks instead of pound signs ('2/2/2007').
< Date() - 30
Uses the Date function to return all dates more than 30 days old.
Date()
Uses the Date and the DateAdd functions to return all records
D t A
", 3,
Date())
Is Null
Is Not Null
Returns all records that contain any value (that are not null).
"
Returns all records that contain a zero-length string. You use zerolength strings when you need to add a value to a required field, but
you don't yet know what the actual value is. For example, a field
might require a fax number, but some of your customers might not
have fax machines. In that case, instead of entering a number, you
enter a pair of double quotation marks with no space between them
" .
3.3.1.
Field
query
NewFieldName : OldFieldName
SETEC University
E.g 2. Full
First
& & L st
3.3.2.
1.
2.
3.
Aggregate function:
Select Query
Ribbon,
Show/Hide,
Design View
Total grid
Total grid
4.
Total grid,
Aggregate function
x,
fields
in,
Page 45 of 140
5.
SETEC University
Run
3.3.3.
Expression Builder:
1.
Select Query
2.
Field
3.
Ribbon,
: Right-click
Page 46 of 140
Design View
Query Setup,
Icon: Builder
Builder
SETEC University
4. Double-Click
folder: Function
functions Double-click
5.
Built-In Function
function
function
OK
function
6. Run query
Lab1:
Select Query
1.
Aggregate function
database Northwind.accdb
2.
Select Query
table Products
a. Group by CategoryID
b. Sum on UnitsInStock
3. Save query
qryUnitsInSto k y
t gory
database Northwind.accdb
2.
Select Query
table OrderDetails
fields: OrderID,
field
Page 47 of 140
SETEC University
4. S v qu ry s qrySu Tot l
3.3.4.
Function
ss
,F il
E.g. 3 L ngu g
IIf
Lab 1:
1.
2.
table Products
: ProductID, ProductName,
UnitInStock
3.
field
StockStatus
UnitsInStock=0
ro u t out of sto k
ro u t not out of sto k
4. Save query
Page 48 of 140
SETEC University
Lab:
1.
database Northwind.accdb
2.
Select Query
table Products
: ProductID, ProductName,
UnitsInStock, UnitPrice
3.
field
UnitPrice 1 - 20
ntion V ry h
UnitPrice 21 - 50
ntion h
UnitPrice 51 - 70
UnitPrice > 70
4. Save query
3.3.5.
Mention
qry ro u t
Build-In-Function
ntion
:
Avg(expr): Average
DateAdd(Interval,Number,Date): Add to
date by interval
DateDiff(Interval,Date1,Date2): Date2
interval
* Interval :
Year
yy, yyyy
Quarter
q, q
Month
mm, m
Page 49 of 140
* Interval :
SETEC University
Day
dd, d
Week
wk, ww
Hour
hh
Minute
mi, n
Second
ss, s
Milisecond
ms
Ex D t
rt yyyy,D t
DateAdd(Interval,Number,Date):
interval
E.g. : D t A
yyyy,10, Hir D t
DateDiff(Interval,Date1,Date2):
Date2
Date1
interval
E.g. : D t Diff yyyy, irthD t , ow
DatePart(Interval,Date):
interval
E.g. : D t
rt ,
irthD t
D t
rt m,
irthD t
D t
rt yyyy,
irthD t
irthD t , yyyy
kup D t
Database file
Office button
Page 50 of 140
:
Back up
Manage
Back Up Database
Chapter 3: Creating and Using Query
SETEC University
3.
4.
5.
3.5.
File name,
Database file
Database file
Back up
Save
Delete Query:
table
1.
S l
u ry
2.
Ribbon,
3.
Query Type,
Design View
Delete grid
Page 51 of 140
SETEC University
Delete grid
4.
field
Field:
Table:
Delete:
record:
field
table
+ From:
+ Where:
field
table
record
field
Page 52 of 140
SETEC University
6.
L
Yes
records
D l t
1.
u ry
records
(UnitsInStock)
30
2.
table: Orders
3.
table: Orders
OrderID
10500
ID = LAUS
4.
table: Products
(CategoryName)
Seafood
3.6.
Update Query:
table
1.
S l
u ry
2.
Ribbon,
3.
Query Type,
Design View
Update grid
Page 53 of 140
SETEC University
Update grid
4.
fields
Field:
Table:
Update To:
Criteria:
fields
field
Update record
Update record
table
Page 54 of 140
SETEC University
6.
Yes
Lab:
Update query
1.
Country=
2.
Update
xi o
m o i
table: Customers
Unit ri
ro u ts
stock
3.7.
Append Query:
record
1.
S l
2.
Ribbon,
3.
Query Type,
table
u ry
Design View
Source table
4.
Icon: Append
Anoth r D t
Destination table
s
record
record
table
database
Page 55 of 140
5.
OK
Field:
Table:
Append To:
Criteria:
SETEC University
fields
Field
fields
Append
Source table
Source table
Field
Destination table
7.
Yes
Page 56 of 140
SETEC University
t App n
1.
u ry
table
Clients
2.
table: Customers
table Customers
ountry=
xi o
table Clients
3.
table Customers
fax
table Clients
4.
table Customers
Germany
table Clients
5.
table Customers
Canada
UK
table Clients
E.g.:
< Date() - 30
Betw
nD t
", 3, D t
Returns ll r
or s
tw
n to
ys date
Make-table Query:
table
1.
S l
u ry
2.
Ribbon,
3.
Query Type,
Design View
tables
4.
table
record
Page 57 of 140
5.
SETEC University
Current Datab s
table
Database
Anoth r D t
table
database
OK
6.
fields
fields
table
8.
Yes
Page 58 of 140
SETEC University
Lab:
1.
2.
Make-table query :
database Northwind.accdb
t
CustomerAG
Address
ity
A
3.
table: Customers
ustom rLon on
London
t
UnitPrice
ID
ContactName, Address
4.
ity
ri
fields: CustomerID,
table: Customers
Madrid
ro u t otSE
UnitsInStock
table: Products
s
Page 59 of 140
3.9.
SETEC University
Parameter Query:
Query
1.
S l
2.
u ry
Design View
fields
tables
field
Parameter
Query
3.
Parameter Query
Criteria
field
Page 60 of 140
Parameter
SETEC University
query
table: Orders
(OderDate)
2.
query
(Begin Date
table: Products
stock
3.
End Date)
query
table: Customers
(CompanyName)
4.
query
table: Customers
omp ny
Page 61 of 140
3.10.
SETEC University
Crosstab Query:
Query
Column Heading
Row Heading
1.
Ribbon,
tab: Create
Win ow
2.
Page 62 of 140
rosst
Other,
u ry
u ry Wiz r
OK
SETEC University
3.
table
query
Crosstab Query
Next
4.
field
Row Heading
Next
Page 63 of 140
5.
6.
field
interval
Page 64 of 140
field
SETEC University
Column Heading
Next
Date/Time
SETEC University
7.
field
function
field
Next
8.
query
Finish
Page 65 of 140
Lab:
1.
SETEC University
Crosstab query:
database Northwind.accdb
2.
crosstab query
table Customers
ountry
3.
(City)
crosstab query
customers
table Orders
4.
Wizard,
crosstab query
(Freight)
(CompanyName)
Page 66 of 140
table: Orders
Shippers
(ShipCountry)
SETEC University
SQL Statement
SQL
relational databases
a)
Microsoft Access
SQL:
1.
Ribbon,
2.
Other,
3.
Show Table,
4.
tab: Create
Icon: Query Design
Close
Result,
Icon: SQL
Page 67 of 140
b)
SETEC University
Run SQL:
Ribbon,
Result,
Icon:
Run
c)
View SQL:
Ribbon,
tab: Home
Page 68 of 140
SETEC University
Description
Predicate
Specifies that all fields from the specified table or tables are selected.
Table
The name of the table containing the fields from which records are
selected.
field1, field2
The names of the fields containing the data you want to retrieve. If you
include more than one field, they are retrieved in the order listed.
alias1, alias2
tableexpression
The name of the table or tables containing the data you want to retrieve.
queries
1.
SQL Statement:
database Northwind.accdb
2.
SQL
a.
b.
:
ustom rID, ont
ro u t
m , Unit ri
Or
rID, Or
L st
Descending
ustom rs
UnitsInStock
UnitsInSto k
rD t , Fr ight
(Freight)
e.
r ss
table: Products
stock
d.
c.
First
(UnitPrice)
Ship
table: Products
table: Orders
table: Employees
sort
LastName
Page 69 of 140
SETEC University
f.
g.
h.
Or
rs
OrderID,
Or
i.
r D t ils
Sort: Ascending
CompanyName
j.
omp ny
Subquery
k.
ContactName, Address
Country
Country, ContactName
Page 70 of 140
SETEC University
Chapter 4
Creating and Using Form
Form?
Form
Object
MS-Access
table
4.1.
query
Form
Form tool:
1.
Navigation Pane,
2.
Ribbon,
3. Access
interface
table
tab: Create
form
query
Form,
Layout view
Form
icon: Form
Page 71 of 140
4.
Save
5.
OK
4.2.
1.
SETEC University
save form
View form:
Navigation Pane, Double-click
view
Page 72 of 140
form
form
Form View:
SETEC University
2.
Ribbon,
:
-
tab: Home
icons
Views,
icon: View
Status bar
Form View:
user
Page 73 of 140
Layout View:
SETEC University
form
(formatting)
Design View:
form
(formatting)
Layout View
4.3.
1.
Form
Navigation Pane,
Page 74 of 140
query
Form
SETEC University
2.
Ribbon,
3. Access
tab: Create
form
Forms,
Layout View
Form View
Datasheet View
Page 75 of 140
4.4.
Form
1.
Navigation Pane,
2.
Ribbon,
3. Access
Page 76 of 140
SETEC University
table
tab: Create
form
query
Form,
Layout View
Form
SETEC University
4.5.
Form
1.
Ribbon,
Wizard
tab: Create
Form,
More Forms
Form Wizard
2.
Wizard
3.
4.
T
List Av il
l s
u ri s ,
l Fi l s,
t
fi l s
query
form
Next
Page 77 of 140
5.
layout
form
SETEC University
olumn r, T
ul r, D t sh
t,
Next
6.
style
form
Next
Page 78 of 140
SETEC University
7.
form
information.
4.6.
form
1.
Ribbon,
title bar
Op n th form to vi w or nt r
Finish
2.
Forms,
Layout View
Page 79 of 140
3.
SETEC University
(+)
table
fields
table
4. Double-click
field
form
fields
key: Ctrl +
fields
5.
tools
Control
tab: Format
Logo,
form
Page 80 of 140
SETEC University
6.
control
-
4.7.
1.
Design view
Ribbon,
2. Right-click
Right-click
tab: Design
control
form
form:
form
tools
Design View
Controls
form:
Design View
control
control
Layout
Remove
3.
Mouse pointer
Controls
Page 81 of 140
4.
SETEC University
Control
Mouse pointer
Controls
4.8.
form :
Cursor
Tab:
Shift + Tab:
Ctrl + Home:
Ctrl + End:
Page 82 of 140
field
Cursor
field
field
Cursor
Cursor
Cursor
record
record
Form
Form
SETEC University
4.9.
Main form
Main form
Subform
Subform
tables
1.
Columnar Form
Subform
Tabular
Datasheet Form
form
Subform
Many
Main form
Form
One
Subform
Ribbon,
Form Wizard
tab: Create
Forms,
Wizard
2.
3.
window
Form Wizard
Tables/Queries,
4. Double-click
5.
table/query
fields
Wizard
table/query
Main form
Main form
Tables/Queries,
Subform
6. Double-click
fields
Subform
Page 83 of 140
7.
SETEC University
Next
8.
Form
with su form s
9.
Page 84 of 140
Next
SETEC University
10.
11.
12.
layout
subform
: Tabular
Datasheet
Next
style
Next
Page 85 of 140
13.
Main form
SETEC University
Subform
Op n th form to vi w
or nt r inform tion
14.
Finish
Subform
1.
Page 86 of 140
Main form
form
Columnar
SETEC University
2.
Subform
Tabular Form
4.
Ribbon,
Datasheet Form
Design View
tab: Design
Controls,
Wizards
5.
Navigation Pane,
Subform
Detail
Main
form design
Page 87 of 140
6. Access
SETEC University
Subform
Main form
Relationship
Database
***
Access
1.
Subform
Main form
2.
form design,
3.
Ribbon,
Tools,
4.
Source Object:
Page 88 of 140
Design
Subform
tab: Design
Property Sheet,
-
Main form
tab: Data
Properties
form
Subform
SETEC University
Main form
Subform
-
Subform
Main form
5. View form
Form View
Main form
2.
Subform
3.
Subform
table: Customers
table: Orders
Main form
code
Windows
Application
Microsoft
a. What is Object?
Object
Control
Page 89 of 140
Text Box :
SETEC University
Control
keyboard
-
Label :
Control
Control
Command Button :
Control
button
event
-
ox
Control
check
uncheck
-
Option Button :
Control
Object
Control
ontrols
Form
MS-
form
form
.Top :
form
.Height:
Control
.Width:
Control
object
ObjectName.MethodName
E.g. :
txtFirstName.SetFocus
Me!txtLastName.Undo
rs.MoveNext
rs.MoveFirst
a.3. What is Event?
Event
(Procedure)
user
program code
E.g.:
Private Sub btnOK_Click()
Statements
End Sub
Page 90 of 140
SETEC University
form
Design view
Ribbon,
c.
Tab: Create
Code
View form
vi w o
Design View
Form Design
form
Form Design Tools,
Tab: Design
View Code
d.
event
Click
control
event
1.
Property windows,
tab: Event
button
: Right-click
Lab:
control
Form
control
OK
Code
Form
txtFirstName
txtLastName
txtAddress
btnClear
btnOK
2.
Code Editor,
code
Page 91 of 140
SETEC University
memory
application variable
memory
E.g.1:
Private Sub Detail_Click()
SomeColor = vbRed
Detail.BackColor = SomeColor
End Sub
-
(declare) variable
variable
Dim
Dim VariableName
E.g.:
Private Sub Form_Load()
Dim thisVar
thisVar = 15
MsgBox thisVar
End Sub
-
Option Explicit:
variable
(Error)
E.g.:
Private Sub Form_Load()
Dim thisVar
thisVar = 15
MsgBox thisInt
End Sub
Option Explicit
Code Builder
variable
E.g. :
variable
Option Explicit
Private Sub Form_Load()
.....
End Sub
Page 92 of 140
SETEC University
Option Explicit
1.
menu
2.
Code Builder:
tab: Editor
R quir V ri
l D
Tools Option
Code Settings,
check
k ox
l r tion
variable
VariableName2
As
:
Data
Type
(Range)
Description
(0 to 255)
Byte
Integer
2-byte integer
( 32,768 to 32,767)
Long
4-byte integer
( 2,147,483,648 to 2,147,483,647)
Single
Double
Currency
8-byte number
with fixed decimal
point
String
Date
( 3.402823E38 to 1.401298E
45 (negative values))
1.401298E 45 to 3.402823E38 (positive values)
( 1.79769313486231E308 to
4.94065645841247E 324 (negative values))
4.94065645841247E 324 to
1.79769313486231E308 (positive values)
( 922,337,203,685,477.5808 to
922,337,203,685,477.5807)
String of
characters
characters)
8-byte date/time
value
(January 1, 100 to
December 31, 9999)
variable
(Prefix)
variable
Chapter 4: Creating and Using Form
Page 93 of 140
SETEC University
Data Type
Prefix
Example
Boolean
bln
blnFound
Byte
byt
bytTracks
Date/Time
dtm
dteStartOfShift
Double
dbl
dblDistance
Error
err
errCantOpen
Integer
int
intNbrOfStudents
Long
lng
lngPopulation
Object
obj
objConnection
Single
sng
sngAge
String
str
strCountryName
Currency
cur
curHourlySalary
Variant
var
varFullName
- Functions
CBool():
convert
CStr():
Boolean
convert
CByte():
convert
Lng
convert
Long
String
CSng
convert
Single
Byte
CDbl:
convert
Double
ur
convert
Currency
(Small number)
Int
convert
Integer
D t
Constant:
convert
variable
Date
E.g. :
Static
constant
keyword
sub procedure
variable
Static
variable
function
keyword:
memory
function
Page 94 of 140
sub procedure
SETEC University
E.g. :
Sub Calculate()
Static intVar As Integer
intVar = intVar + 1
MsgBox intVar
End Sub
Private Sub btnCalculate_Click()
Call Calculate
End Sub
Lab:
Data Type:
1.
form
2.
form
On
3.
li k
Design View
Property windows,
tab: Event
event
button
code
form
Design View A
Caption: Calculate
Name: btnCalculate
5.
ontrol
omm n
utton
code
Sub Calculate()
Static intVar As Integer
intVar = intVar + 1
MsgBox intVar
End Sub
-
event: On Click
button: Calculate
code:
frmSt ti V ri
l
Page 95 of 140
***
SETEC University
MsgBox function:
message
dialog box
constant
button
click
user
click
button
user
icon
buttons
-
prompt:
string
expression
message
dialog
box
-
button:
buttons
Constant
prompt
Value
Description
vbOKOnly
vbOKCancel
vbAbortRetryIgnore
vbYesNoCancel
vbYesNo
vbRetryCancel
vbCritical
16
vbQuestion
32
vbExclamation
48
vbInformation
64
vbDefaultButton1
vbDefaultButton2
256
vbDefaultButton3
512
vbDefaultButton4
768
Constants
VBA
code
Page 96 of 140
constants
SETEC University
titl
Numeric Value
vbOK
vbCancel
vbAbort
vbRetry
vbIgnore
vbYes
vbNo
string
Title bar
Message Box
E.g. :
Private Sub Detail_Click()
MsgBox "Do you really want to delete this record?", _
vbYesNoCancel Or vbQuestion, "Confirmation"
End Sub
buttons
MsgBox
Dim x As Integer
x = MsgBox("Do you really want to delete this record?", _
vbYesNoCancel + vbQuestion, "Confirmation")
code
Yes, No
MsgBox
Cancel
constant vbYes=6
***
button: Yes
x
InputBox Function:
message
button
buttons
user
dialog box
string
text
click
text box
Page 97 of 140
prompt
f ult
title:
text
SETEC University
Message Box
text box
user
E.g. :
Private Sub Form_Load()
Dim x As Integer, y As Integer
Dim sum As Integer
x = InputBox("Please enter value of x", "Enter value of x")
y = InputBox("Please enter value of y", "Enter value of y")
sum = x + y
MsgBox "The sum of " & x & " and " & y & " is " & sum,
,"Result"
End Sub
Page 98 of 140
SETEC University
Lab :
Form
1.
Code:
form
Add buttons
click
properties
Name
Caption
Events
btnSum
Sum
On_Click
btnSubtract
Subtract
On_Click
btnMultiply
Multiply
On_Click
btnDivide
Divide
On_Click
buttons
(x
2.
, access
InputBox
user
y)
code
Page 99 of 140
SETEC University
code
program
ro
ur s
Procedure
Function Procedure
Procedure
return
(Call)
4.13.1.
VBA
Sub
procedures
Sub Procedure
Function
return
Sub Procedure:
Sub ProcedureName([Arguments])
Statements
End Sub
E.g. :
Sub Multiply()
Dim x As Integer, y As Integer
Dim result As Integer
x = txtValue1
y = txtValue2
result = x * y
txtResult = result
End Sub
-
SETEC University
E.g. :
Private Sub btnCalculate_Click()
Call Multiply
End Sub
-
Sub Procedure
Arguments
Function Procedure:
Function Procedure
As
Sub Procedure
return
DataType
return
E.g. :
Function Divide() As Integer
Dim x As Integer, y As Integer
x = txtValue1
y = txtValue2
Divide = x / y
End Function
-
Function Procedure
statements
Procedure
variable
Sub Procedure
Sub
return
text box
E.g. :
Private Sub btnCalculate_Click()
txtResult = Divide
End Sub
Lab:
1.
SETEC University
Sub Procedure:
form
2.
Sub Procedure
3.
Sub Procedure
4.
click
button: Calculate
5.
click
button: New
clear
text box
Sub SquareSolution()
Dim dblSide As Double
Dim dblPerimeter, dblArea As Double
dblSide = txtSide
dblPerimeter = dblSide * 4
dblArea = dblSide * dblSide
txtSqPerimeter = dblPerimeter
txtSqArea = dblArea
End Sub
Private Sub RectangleSolution()
Dim dblLength, dblHeight As Double
Dim dblPerimeter, dblArea As Double
dblLength = txtLength
dblHeight = txtHeight
dblPerimeter = (dblLength + dblHeight) * 2
dblArea = dblLength * dblHeight
txtRecPerimeter = dblPerimeter
txtRecArea = dblArea
End Sub
Page 102 of 140
SETEC University
Function Procedure:
Function Procedure
Procedure
Arguments:
Function Procedure
Call Function ro
ur
Arguments
Lab:
1.
SETEC University
2R
txtEllipseCircumference = dblCircum
txtEllipseArea = dblArea
End Sub
2.
Function Procedures
Function BoxArea(dblLength As Double, _
dblHeight As Double, _
dblWidth As Double) As Double
Dim Area As Double
Area = 2 * ((dblLength * dblHeight) + _
(dblHeight * dblWidth) + _
(dblLength * dblWidth) _
)
BoxArea = Area
End Function
Function BoxVolume(dblLength As Double, _
dblHeight As Double, _
dblWidth As Double) As Double
Dim Volume As Double
Volume = dblLength * dblHeight * dblHeight
BoxVolume = Volume
End Function
Homework
HW1:
Sub Procedure
HourW g
txtHours
txtHWage
txtResult
btnE&xit
SETEC University
Function Procedure
(Marked Price)
discount
(Discount Rate)
SETEC University
Meaning
Example
Opposite
Equality to
a=b
Not
Not
Not equal to
12 <> 7
<
Less than
25 < 84
>=
<=
>
>
Greater than
248 > 55
<=
>=
<
End If
SETEC University
Lab:
Conditional Statements:
1.
Password Form
frmLogin
Textboxs:
-
txtUserName
Command buttons:
2.
code
event On_Click
button: Login
code
event On_Click
button: Login
computer
Th Do Whil Loop
Do While Condition
Statement(s)
Loop
SETEC University
Th DoLoop Whil
Do
Statement(s)
Loop While Condition
Th Do UntilLoop
Do Until Condition
Statement(s)
Loop
E.g.:
Private Sub cmdCounter_Click()
Dim Answer As String
Do Until (Answer = "1")
Answer = InputBox("Are we there yet (1=Yes/0=No)?", _
"Counter", "1")
Loop
MsgBox "Wonderful, we have arrived"
End Sub
-
Th DoLoop Until
Do
Statement(s)
Loop Until Condition
Th For ext:
For Counter = Start To End Step Increment
Statement(s)
Next Counter
SETEC University
Programming interface
database
Microsoft
2. Recordset
object
query
DAO
records
database
3.
table
Database Object
Dim db AS DAO.Database
4.
Recordset Object :
Dim RecordsetName AS DAO.Recordset
E.g. :
Dim rs AS DAO.Recordset
5.
Database Object :
Set db = CurrentDb() :
Database Object
Database
Set db = DAO.OpenData
Database
th\Fil
m .m
Database Object
E.g. :
Set db = DAO.OpenDatab s D \My Databases\StudentDB.acc
6.
Recordset Object
S t rs =
.Op nR
or s t T
l |qu ry, R
or Typ
*RecordType:
-
Lab1:
DAO
SETEC University
Form :
Form
txtSubjectID
txtSubjectName
txtDescription
btnLast
btnNext
btnPrevious
Database
Recordset
btnFirst
Option Explicit
Dim db As DAO.Database
Dim rs As DAO.Recordset
Sub showDT()
txtSubjectID.Value = rs.Fields("SubjectID")
txtSubjectName.Value = rs.Fields("SubjectName")
txtDescription.Value = rs.Fields("Description")
End Sub
-
Database
Recordset
Form_Load() :
code
record :
code
record
SETEC University
code
record
code
record
records :
btnSearch
btnClear
code
records:
Lab 3:
Add record
SETEC University
btnAdd
code
Add records:
record :
btnDelete
code
Delete records:
SETEC University
Lab 5:
Update record:
btnUpdate
code
Add records:
SETEC University
Chapter 5
Creating and Using Report
Report?
Report
Object
MS-Access
query
5.1.
table
R port
1.
Report tool:
Navigation Pane,
Table
Query
Report
2.
Ribbon,
tab: Create
Reports,
icon: Report
Report
3.
5.2.
1.
Save
Layout View
Save report
View Report
Navigation Pane, Double-click
view
Report
Report
Report View
SETEC University
2.
Ribbon,
:
-
tab: Home
icons
icon: View
Status bar
Report View:
Report
Views,
Report
Clipboard
Print Preview:
Layout View:
SETEC University
Report
Report
(design)
Design View:
Report
Layout View
(formatting)
SETEC University
5.3.
1.
R port
Report Wizard
Ribbon,
tab: Create
Report,
2.
3.
l s
List Av il
u ri s ,
l Fi l s,
fields
T
4.
query
fields
Report
fields
l s
u ri s
Report
table
query
table/query
Next
5.
field
6.
SETEC University
grouping levels
fields
Next
(Sort)
Detail records
Next
SETEC University
7.
Layout
-
Stepped:
Block:
Orientation
Report
8.
9.
SETEC University
Outline:
Next
Style
Next
SETEC University
10.
Report
11.
r vi w th r port
Finish
5.4.
Label
1.
Label Wizard
table
query
Label
2.
Ribbon,
tab: Create
Reports,
icon: Label
3.
Label Wizard
:
4.
Label
5.
6.
SETEC University
Text
fields
Label
Next
Next
mailing label
Next
SETEC University
7.
field
8.
Report
9.
(Sort)
th l
Next
Finish
5.5.
R port
1.
SETEC University
Ribbon,
tab: Create
Report,
2.
(+)
Table
table
3. Double-click
field
Report
fields
key: Ctrl +
fields
4.
tools
Control
Logo,
tab: Format
Report
Page 124 of 140
SETEC University
5.6.
Report Sections:
Report
Report
:
Header:
Report
Logo,
Page Header
Report
Group
Header
Records
Records
Detail
Group
Row
Record Source
Footer:
Records
(Aggregate Functions)
Page Footer
Report Footer:
Report
Report
5.7.
Grouped Report
Record Source:
1.
SETEC University
Report Wizard:
Select Query
tables: Customers
Orders
fields:
2. Save query
Report Wizard:
1.
Ribbon,
tab: Create
Wizard Report
Report,
SETEC University
2.
Tables/Queries,
Source
3.
query
Record
Report
list Av il
table
l Fi l s,
fields
Report
Next
4.
Next
5.
SETEC University
field
group
field
(Data Type)
Date/Time
i on Grouping Options
Grouping intervals
6.
OK
Next
SETEC University
7.
fields
(Sort)
Detail records
-
i on Summ ry Options
Max)
OK
Next
9.
Layout
10.
Next
11.
Style
SETEC University
Orientation
Report St pp
, lo k, Outlin
Next
SETEC University
12.
13.
Report
r vi w th r port
Finish
Lab: report
SETEC University
Solution:
5.8. Homeworks
1. tblCustomers
2. tblProducts
3. tblOrders
SETEC University
4.
tblOrderDetails
5. relationships tables :
SETEC University
frmOrders
frmOrderDetailProducttSub
cboSearch
a. code event: After_Update cboSearch :
Private Sub cboSearch_AfterUpdate()
Dim SQL As String
SQL = "Select * from tblCustomers Where CustomerName='"
_
& cboSearch & "'"
Form_frmCustomerOrder.RecordSource = SQL
End Sub
b. frmOrder
subform frmCustomerOrder
buttons :
SETEC University
frmCustomerOrder
frmOrders
btnPreviewReport
btnPrintReport
c d report
SETEC University
rptOrders
rptOrderDetailProducttSub
rptOrder
subreport rptCustomerOrder
SETEC University
rptCustomerOrder
rptOrders
SETEC University
b. property txtNo :
-
Control Source: =1