You are on page 1of 27

http://lnui.

vn 1
Microsoft Access 2003
TRNH B CHNG CH QUC GIA
Bi ging
L XUN NUI
i hcTin hc
C S TIN HC XUN NUI
inthoi: (068) 3.854.854 - 0121.23.23.555
Website: lnui.vn
(Ti liu lu hnh ni b)
http://lnui.vn 2
M u Query Table
Microsoft Access 2003
Ni dung
M u: Gii thiu v Microsoft Access
Bng (Table)
Truy vn d liu (Query)
Lm vic vi mu biu (Form) - Command Button
Bo biu (Report)
Macro - Menu
Form Report Macro
http://lnui.vn 3
I. Gii thiu
Access l mt h qun tr c s d liu mnh chy trn mi
trng Windows
Access 2003 l mt phn trong b chng trnh Microsoft
Office 2003 c dng rt rng ri hin nay
Access cho php ngi s dng qun l, bo tr, khai thc, lu
tr s liu mt cch c t chc trn my tnh
Vi Access, ngi s dng khng cn vit tng cu lnh nh
Pascal, Foxpro, C... m ch t chc d liu v thit k cc yu
cu, cng vic cn gii quyt
Query Table M u
Chng I: Gi i thiu v Microsoft Access 2003
Form Report Macro
http://lnui.vn 4
II. Cc khi nim c bn
C s d liu(Database): ltphpccd liuphcv chomt mc
ch, bi tonc th. V d nh CSDL chobi tanqunllng, bi
tonQunlsinhvin
C s d liuquanh (Relational Database): D liuct chc
thnhccbnghai chiu.
* Chiudc: ltphpccc im cai tng cnqunl(gi l
trng- Field)
Vd: Sinh vin (tn, ngy sinh, lp, im)
Mt hng (tn hng, s lng, n gi,...)
* Chiungang: lgitr cacctrng(ccbnghi - Record)
Vd: (L Xun Nui, 30/5/1965, TB, 9)
Query Table M u Form Report Macro
http://lnui.vn 5
Table (bng): l thnh phn c bn ca CSDL, n cho php
lu tr d liu phc v cng tc qun l. Cc bng trong mt
CSDL thng c mi quan h vi nhau
Query (truy vn): l cng c dng tnh ton cc trng
khng cn lu tr (imTB, thnh tin), sp xp, tmkim,
tng hp d liu
i vi Access, c s d l iu (CSDL) bao gm:
II. Cc khi nim c bn
M u Query Table Form Report Macro
http://lnui.vn 6
II. Cc khi nim c bn
Form (Biu mu): gip NSD thc hin vic nhp,
xut phong ph, khng n iu nh nhp xut trn
Table hay Query
Report (Bo biu): cho in n vi cc kh nng
In d liu di dng bng biu
Sp xp d liu trc khi in
In d liu c quan h trn mt bo co
Query Table M u Form Report Macro
http://lnui.vn 7
Macro (tp lnh): l mt tp hp cc lnh nhmthc hin
cc thao tc thng gp.
Module (n th): l mt dng t ng ho chuyn su
hn Macro. l nhng hmring ca NSD c vit bng
ngn ng Access Basic
Tptin chng trnh do Access to rac kiul .MDB
Query Table M u Form Report Macro
http://lnui.vn 8
III. Khi ng, thot
Khi ng: Chn Start / Program / Microsoft Access hoc chn
biu tng Microsoft Access (hnh cha kho) trn mn hnh nn
hay trn thanh cng c (nu c), xut hin mn hnh sau:
Query Table M u Form Report Macro
http://lnui.vn 9
III. Khi ng, thot
Create a new database using
Blank Access database: to mt CSDL mi
Access database wizards, pages, and projects: to mt CSDL mi vi
cc dng c sn ca Access
Open an Existing Database: m mt CSDL c
Sau khi chn mt trong ba mc trn, chn OK
Nu khng thc hin cc chn la trn th chn Cancel vo thng
mn hnh Access
Thot: chn lnh File / Exit (Alt+F4)
Nu cha lu d liu trc khi thot s
c thng bo
Query Table M u Form Report Macro
http://lnui.vn 10
Gm cc thao tc:
M u Query Table
To bng mi , nhp d liu vo bng
Thit lp quan h gia cc bng
S dng thuc tnh ca trng trnh by dng d
liu , kim tra t nh hp l ca trng khi cp nht
Chng II : Bng (Table)
Form Report Macro
http://lnui.vn 11
I. To cu trc ca bng (bng Design View )
Khi ng Access, trong hp thoi MS Access, chn Blank
Access Database, OK
T ca s Database,
chn Table /New, xut
hin hp thoi New
Table cho php chn
cch to Table:
Xut hin hp thoi File New Database
G tn CSDL, chn Create, xut hin ca s Database
M u Query Table Form Report Macro
http://lnui.vn 12
I. To cu trc ca bng
Cho to bng theo
nhu cu ca NSD
Trong hp thoi
New Table, chn
Design View, OK.
Ca s nh ngha
cu trc bng c cc
phn
M u Query Table Form Report Macro
http://lnui.vn 13
I. To cu trc ca bng
Bc 1: Khai bo tn trng (Field name): bt buc, t tu (<=64 k t),
c th c khong trng
Bc 2: Khai bo kiu d liu (Data type) tng ng ca trng: bt buc.
Chn mt trong cc kiu
Chn mt tr t danh sch cc tr Lookup Wizard
Cha gi tr logic (True/False) Yes/No
Gi tr s (Access t tng 1 n v cho mi bn ghi mi) Auto Number
Cha gi tr tin t Currency
Cha gi tr ngy, gi Date/Time
Cha gi tr s Number
Cha tp hp cc k t tu , <=65535 k t Memo
Cha tp hp cc k t tu , <=255 k t Text
ngha Kiu
M u Query Table Form Report Macro
http://lnui.vn 14
I. To cu trc ca bng
Bc 3: Field properties: tng ng vi mi kiu d liu, khai
bo thm cc thuc tnh, gm thuc tnh chung (General) v
thuc tnh nhp s liu (Lookup)
M u Query Table
Bc 4: Sau khi thit k xong cu trc bng, ghi ln a bng
mt trong cc cch
Chn lnh File / Save (Ctrl+S hoc biu tng Save)
Hoc ng ca s Table, Access
s hi c lu khng, chn Yes
lu.
Form Report Macro
http://lnui.vn 15
I. To cu trc ca bng
Nu cha to kho chnh (Primary
Key), Access s hi c to khng
No: cu trc bng c ghi nh thit k
Yes: Access t thm trng c tn ID lm kho chinh
G tn bng vo mc Table
Name
M u Query Table
Bn nn chn No
Form Report Macro
http://lnui.vn 16
Trong ca s Database, chn
trang Table
Chn tn bng cn
nhp, chn Open
Trang Table
Bng cn nhp
Chn Open
Nhp d liu
M u Query Table
Bc 5: nhp d liu cho bng
Form Report Macro
http://lnui.vn 17
II. Gii thiu cc thuc tnh ca trng
1. Cng dng:
iu khin hnh thc th hin d liu
Nhp d liu theo mu
Kim tra d liu, ngn cn vic nhp sai
Tng tc tm kim
M u Query Table Form Report Macro
http://lnui.vn 18
II. Gii thiu cc thuc tnh ca trng
2. Tng quan v cc thuc tnh ca trng
To ch mc tng tc tm kim trn trng ny Indexed
Nu chn Yes, bt buc phi vo d liu cho trng Require
Nu chn Yes cho php vo chui k t rng(Text, Memo) AllowZero Length
Thng bo xut hin khi NSD vo d liu vt qu gii hn qui
nh mc Validation Rule
Validation Text
Qui tc d liu hp l, d liu phi tho mn qui tc ny mi
c nhp
Validation Rule
Xc nh gi tr mc nh ca trng Default Value
t tiu cho trng (s hin th khi nhp liu thay v tn
trng)
Caption
Qui nh mt n nhp liu Input Mask
S ch s thp phn trong kiu Number v Currency Decimal Place
Dng hin th d liu kiu ngy v s Format
S k t ca trng Text, hay di ca trng Number Field Size
ngha Thuc tnh
M u Query Table Form Report Macro
http://lnui.vn 19
II. Gii thiu cc thuc tnh ca trng
3. Chi tit v cc thuc tnh ca trng
Thuc tnh Field Size
Trng Number
-1.797*10
308
1.797*10
308
Double
-3.4*10
38
3.4*10
38
Single
-2147483648 2147483648 Long Interger
-32768 32767 Integer
Min gi tr Field Size
M u Query Table
C th chn cc
kiu sau
Thuc tnh Format
Trng Text
Bin ch thng thnh ch hoa >
Bin ch hoa thnh ch thng <
Khng bt buc phi nhp k t vo vn bn &
Bt buc phi nhp k t vo vn bn @
Cng dng K t
Form Report Macro
http://lnui.vn 20
II. Gii thiu cc thuc tnh ca trng
3. Chi tit v cc thuc tnh ca trng
Thuc tnh Format
Trng Number
82.5% 0.825 Percent
1,234.50
1234.50
$1234.5
1234.5
Trnh by
1234.5 Standard
1234.5 Fixed
1234.5 Currency
1234.5 General Number
S Dng
M u Query Table
Trng Date / Time:
thng chn kiu
Short Date
10:30 Short Time
10:30 AM Medium Time
10:30:00 AM Long Time
4/23/02 Short Date
23/April/2002 Medium Date
Tuesday, April 23, 2002 Long Date
4/23/02 10:30:00 AM General Date
Hin th Dng
Form Report Macro
http://lnui.vn 21
II. Gii thiu cc thuc tnh ca trng
3. Chi tit v cc thuc tnh ca trng
Thuc tnh Input Mask (mt n nhp liu)
Cng dng
To khun dng nhp liu cho d nhn. Vd: du ngn cch
phn nguyn v thp phn, du gch ngang phn cch
cc cm k t ca ti khon
Kim tra tnh hp l ca k t g vo. (Vd nu qui nh l
ch s th Access s khng nhn cc k t khng phi l
ch s)
T ng bin i cc k t c nhp (Vd t ch thng
sang ch hoa)
Che giu thng tin a vo (Vd khi ta dng Password)
M u Query Table Form Report Macro
http://lnui.vn 22
II. Gii thiu cc thuc tnh ca trng
3. Chi tit v cc thuc tnh ca trng
Thuc tnh Input Mask (mt n nhp liu)
k t bt k, khng bt buc C
k t bt k, bt buc &
k t ch hay s, khng bt buc a
k t ch hay s, bt buc A
ch hoc du cch, khng bt buc ?
mt ch ci, bt buc L
ch s, du cng +, du tr -, du cch #
ch s 0...9, khng bt buc 9
ch s 0...9, bt buc 0
Cng dng : l v tr dnh cho K t
Vd1: nhp s in
thoi dng Text theo
mu:
0-511-810425
ta dng mt n
0-000-000000
Vd2: nhp im thi
cha hai ch s phn
nguyn, mt ch s
phn thp phn ta
dng mt n
00.0
M u Query Table Form Report Macro
http://lnui.vn 23
II. Gii thiu cc thuc tnh ca trng
3. Chi tit v cc thuc tnh ca trng
Thuc tnh Default Val ue
Dng t gi tr mc nh cho trng. Gi tr mc nh ny
c th l mt hng hay mt hm ca Access.
V d: Date(): ngy hin hnh
Thuc tnh Required
Nu chn Yes, bt buc phi nhp d liu vo, nu khng
my s bo li
M u Query Table
Thuc tnh Validati on Rule
Cng dng: Access t ng kim tra tnh hp l khi nhp liu.
Mun chng trnh kim tra, trong biu thc ny, ta t mt
biu thc hp l. V d: >0 (S lng phi >0)
Form Report Macro
http://lnui.vn 24
II. Gii thiu cc thuc tnh ca trng
3. Chi tit v cc thuc tnh ca trng
Thuc tnh All ow Zero Length
Cng dng: Nu chn Yes, s cho php cc trng Text v
Memo nhn cc chui rng
M u Query Table
Thuc tnh Indexed
To ch mc khng cho php cc
gi tr trong trng ny trng lp
Yes (No Duplicate)
To ch mc cho php cc gi tr
trong trng ny trng lp
Yes (Duplicate Ok)
Khng c ch mc No
ngha Gi tr
Cng dng: sp xp mt trng no . Thuc tnh nhn cc
gi tr sau:
Form Report Macro
http://lnui.vn 25
III. To Combo box cho trng (Lookup Wizard)
1. Khi nim
L cch to trng m gi tr nhp vo c chn t danh
sch cc tr. Danh sch ny c lit k trong danh sch
xung (Combo box)
2. Cch to: V d minh ha
Yu cu
Gi s c Table Danh muc nganh
thi c cu trc v ni dung:
Ta cn to Table Danh sach thi sinh
c cu trc nh sau:
M u Query Table Form Report Macro
http://lnui.vn 26
III. To Combo box cho trng (Lookup Wizard)
2. Cch to: V d minh ha
Trng Manganh khi nhp
liu, cc gi tr c chn t
danh sch cc tr
Cch thc hin
Bc 1:Ti ca s thit k
Table, khi to trng
Manganh, ct Data Type,
chn Lookup Wizard..., xut
hin hp thoi Lookup Wizard:
M u Query Table Form Report Macro
http://lnui.vn 27
III. To Combo box cho trng (Lookup Wizard)
2. Cch to: V d minh ha
(2) Chn I will type
in the values that I
want: nu mun gi tr
trong danh sch do
ngi s dng t a
vo
Chn (1), Access s yu cu chn mt Table hay Query lm ngun. Chn
Next, xut hin hp i thoi:
(1) Chn I want the
lookup column to look
up the values in a table
or query: nu mun gi
tr trong danh sch
c ly t table hay
query
M u Query Table Form Report Macro
http://lnui.vn 28
III. To Combo box cho trng (Lookup Wizard)
2. Cch to: V d minh ha
Bc 2: y, ta chn Table Danh muc nganh thi, chn Next,
xut hin hp i thoi:
M u Query Table Form Report Macro
http://lnui.vn 29
III. To Combo box cho trng (Lookup Wizard)
2. Cch to: V d minh ha
Bc 3:
Available Fields: lit k
cc trng c trong Table
Chn Next, xut hin hp
i thoi sau:
M u Query Table
Chn trng ph hp ri
kch nt > a sang
danh sch Selected Fields.
y ta chn trng
Manganh
Form Report Macro
http://lnui.vn 30
III. To Combo box cho trng (Lookup Wizard)
2. Cch to: V d minh ha
Bc 4:
Chn Next, xut hin hp
i thoi sau:
Chn Finish hon
thnh qu trnh
M u Query Table Form Report Macro
http://lnui.vn 31
III. To Combo box cho trng (Lookup Wizard)
2. Cch to: V d minh ha
M table Danh sach thi sinh nhp liu, bn s thy rng, ti
trng Manganh, mt danh sch xung cho bn chn m
ngnh
M u Query Table Form Report Macro
http://lnui.vn 32
III. To Combo box cho trng (Lookup Wizard)
2. Cch to: V d minh ha
Chn (2) t nhp
vo cc gi tr trong
Combo box. Chn Next,
xut hin hp i thoi:
Ln lt nhp vo cc
gi tr trong Col1, (gi s
trong bng DS Nhan
vien) nh sau:
M u Query Table Form Report Macro
http://lnui.vn 33
III. To Combo box cho trng (Lookup Wizard)
2. Cch to: V d minh ha
Chn Next sang bc tip theo, xut hin hp thoi:
Chn Finish hon thnh
M u Query Table Form Report Macro
http://lnui.vn 34
III. To Combo box cho trng (Lookup Wizard)
2. Cch to: V d minh ha
Kt qu khi m bng DS Nhan vien nhp liu, bn s thy
rng, ti trng Phng ban, mt danh sch xung cho bn
chn tn phng ban. Cc tn ny do ta t nhp vo trong cc
bc trn
M u Query Table Form Report Macro
http://lnui.vn 35
IV. Kho chnh
1. nh ngha
Kho chnh l mt hoc nhiu trng xc nh duy nht mt
bn ghi
Li ch ca vic to kho chnh: Access dng kho chnh
to s lin kt gia cc bng
M u Query Table Form Report Macro
http://lnui.vn 36
IV. Kho chnh
2. Cch t kho chnh:
mt trng: a con tr chut n dng cha tn trng cn
chn lm mc kho chnh
kt hp ca nhiu trng:
nhn gi phm Shift sau
chn tt c cc trng cn
chn lm mc kho chnh
Ti ca s thit k Table: Nu mc kho chnh l
Chn lnh Edit / Primary Key
(hoc nhn nt phi, chn
Primary Key, hoc chn biu
tng ): cc trng c
chn s c hnh cha kho
u
PrimaryKey
M u Query Table Form Report Macro
http://lnui.vn 37
IV. Kho chnh
3. Hu kho chnh: Ti ca s thit k Table
Chn li lnh Edit / Primary Key mt ln na (hoc nhn nt
phi, chn Primary Key, hoc chn biu tng ): hnh cha
kho u s bin mt
M u Query Table Form Report Macro
http://lnui.vn 38
V. Lp quan h gia cc bng
1. Cng dng
Access dng quan h m bo nhng rng buc ton vn
gia cc bng lin quan trong cc php: thm, sa, xo mu tin
Ta thng t quan h gia mt trng ca bng ny vi
mt trng ca cc bng khc lin kt d liu gia cc
bng vi nhau (cc trng quan h cng tn, cng kiu)
M u Query Table Form Report Macro
http://lnui.vn 39
V. Lp quan h gia cc bng
2. Cch to
Gi s trong CSDL Vat tu
hang hoa ta c 3 bng vi cu
trc:
Ta s lp quan h cho trng Makho trong bng [Danh muc
kho] v trng Mavattu trong bng [Danh muc vat t u] vi hai
trng Makho v Mavattu trong bng [Hang nhap]
M u Query Table Form Report Macro
http://lnui.vn 40
V. Lp quan h gia cc bng
2. Cch to
Ti ca s Database (1), chn lnh Tools / Relationships,
xut hin mn hnh Show Table (Nu khng xut hin, chn lnh
View/Show Table):
1
Ln lt chn Table cn lp quan h, chn Add. Sau khi chn
xong tt c Table, chn Close ng hp thoi
M u Query Table Form Report Macro
http://lnui.vn 41
V. Lp quan h gia cc bng
2. Cch to
Trong ca s Relationships, ta thit lp cc quan h. C hai
loi quan h trong Access
Quan h mt-mt: mi mu tin ca bng A c mt mu tin
tng ng trong bng B
Quan h mt-
nhiu: mi mu
tin ca bng A
c nhiu mu
tin tng ng
trong bng B
M u Query Table Form Report Macro
http://lnui.vn 42
V. Lp quan h gia cc bng
2. Cch to
Chn mt trng t bng ny v ko sang trng tng ng ca bng quan
h. Gi s ta thit lp quan h cho trng Makho trong bng [Danh muc kho]
v bng [Hang nhap], xut hin hp thoi Edit Relationships
Chn nt Create thit
lp quan h, cui cng c kt
qu sau:
M u Query Table
Chn mt kiu quan h
Form Report Macro
http://lnui.vn 43
V. Lp quan h gia cc bng
3. Ch
Khi nh du mc Enforce Referential Integrity th c th s dng thm
cc tu chn sau
Cascade Update Related Fields: khi sa gi tr ca trng kho trong
bng chnh, gi tr tng ng ca cc bn ghi trong trng quan h s b
sa theo
Cascade Delete Related Records: khi xo mt bn ghi trong bng chnh,
cc bn ghi tng ng trong bng quan h s xo (Vd)
M u Query Table Form Report Macro
http://lnui.vn 44
VI. Cc thao tc d liu ch Datasheet
1. Thm mu tin
Gi lnh Insert /New Record (hoc chn biu tng )
2. Xo mu t in
Chn cc mu tin cn xo
Gi lnh Edit / Delete (nhn phm Delete hoc chn biu
tng )
Ch : Khi xo mu tin, Access s a ra thng bo NSD
xc nhn li c xo hay khng
M u Query Table Form Report Macro
http://lnui.vn 45
VI. Cc thao tc d liu ch Datasheet
3. Sp xp mu ti n
Chn trng cn sp xp
Gi lnh Records / Sort / Sort Ascending - Sort Descending
(hoc chn biu tng )
M u Query Table Form Report Macro
http://lnui.vn 46
VI. Cc thao tc d liu ch Datasheet
4. Lc bn ghi
Chn lnh Records / Filter / Filter By Form, xut hin hp thoi
Filter By Form nh sau:
Mun lc trng no, ta bm chut vo trng , chn gi tr
lm iu kin lc
Nhp phi chut, chn Apply Filter/Sort: Access s lit k cc
bn ghi tho mn iu kin
M u Query Table Form Report Macro
http://lnui.vn 47
Truy vn l mt cng c mnh ca Access dng : tng hp,
sp xp v tm kim d liu
Table
Truy vn cho php NSD thng k s liu (truy vn d liu) theo
mnh, xy dng cc bo co tng hp di nhiu hnh thc
khc nhau trn d liu gc l bng (Table)
I. Khi nim
Chng III : Truy vn d liu (Query)
Query M u Form Report Macro
http://lnui.vn 48
II. Cc l oi truy vn thng dng : C nhiu loi truy vn,
nhng thng dng nht l cc loi sau:
1. Select Query (Truy vn chn s liu): c s dng ph
bin nht, dng :
Chn lc cc mu tin
Thm cc trng mi l kt qu thc hin cc php tnh
trn cc trng ca bng ngun.
a vo cc iu kin tm kim, la chn
Table Query M u Form Report Macro
2. Update Query (Truy vn cp nht): dng sa i ng
lot nhiu mu tin ca mt hay nhiu bng
http://lnui.vn 49
II. Cc l oi truy vn thng dng
3. Delete Query (Truy vn xo s liu): xo mt nhm cc
mu tin t mt hay nhiu bng
4. Crosstab Query (Truy vn tham chiu cho): kt nhm
s liu theo chng loi v hin th s liu di hnh thc ca
mt bng tnh km theo s liu tng hp ngang v dc
Table Query M u Form Report Macro
5. Make Table Query (Truy vn to bng ): cho to mt
bng mi t s liu ca Query
http://lnui.vn 50
III. Cch to truy vn
Thng dng hai cch to truy vn ng vi hai la chn:
in Desi gn view v by using wizard
By using wizard: truy vn c xy dng bng cng c
wizard ca Access, ta ch vic tr li cc cu hi theo yu cu
In Design view: truy vn c thit k tu theo mc ch ca
ngi s dng. Ta thng chn cch ny. Cch thc hin nh
sau:
Table Query M u Form Report Macro
http://lnui.vn 51
III. Cch to truy vn
Bc 1: Trong ca s Database, chn trang Queries, chn
nt New, hp thoi New Query xut hin
Trang Queries
Nt New
Ca s Database
Chn Design View, OK, xut hin ca s nh sau
Table Query M u Form Report Macro
http://lnui.vn 52
III. Cch to truy vn
Table Query M u
Bc 2: chn
ngun d liu cho
truy vn
Ca s Show
Table cho chn cc
bng (Tables), cc
truy vn (Queries)
hoc chn c bng
v truy vn lm
ngun d liu cho
truy vn sp to
Chn ngun d liu ph hp, chn Add. Sau khi chn xong
tt c, chn Close tr v ca s Select Query
Form Report Macro
http://lnui.vn 53
III. Cch to truy vn
Table Query M u
M t ca s Select Query
Phn trn: cha cc bng v truy vn chn lm ngun
Phn di: gi l li thit k QBE (Query By Example) dng
cha cc trng ca truy vn mi cn xy dng
nhn F6
di chuyn
gia 2 phn
Form Report Macro
http://lnui.vn 54
III. Cch to truy vn
Table Query M u
M t ca s Select Query
Field: cha tn trng hoc biu thc lm kt qu truy vn
Table: ghi tn ngun d liu ca trng c chn ti dng
field
Sort: chn cch sp xp d liu ca trng
Criteria: biu thc tiu chun chn lc d liu
Show: chn trng c hin th hay khng
Or: iu kin hoc ca biu thc tiu chun chn lc d liu
(nu c)
Form Report Macro
http://lnui.vn 55
III. Cch to truy vn
Table Query M u
Bc 3: Thit k truy vn theo yu cu
a cc trng vo truy vn: nhn gi chut ko trng thch
hp th vo ct ca li thit k, hoc nhp p ti tn trng
Ghi ch: Cch thm trng biu thc:
Chn mt trng trn hng Field, g tn trng biu thc, du :
(hai chm), biu thc.
V d: Tongdiem: [Diemtoan]+[Diemly]+[Diemhoa]
Bc 4: Lp tiu chun la chn (iu kin tm kim)
Trong Criteria ca trng cn lp biu thc, g biu thc
V d: g vo L1C (tm khch loi phng L1C)
Lu truy vn va to : Gi lnh File / Save
Form Report Macro
http://lnui.vn 56
III. Cch to truy vn
Table Query M u
Ghi ch: Thay i loi
truy vn
Chn lnh Query, chn
trong danh sch loi
Query ph hp
Chn loi
Query
Form Report Macro
http://lnui.vn 57
IV. Thc hin truy vn
Table Query M u
Trong ca s thit k truy vn
Gi lnh Query / Run (hoc chn biu tng trn thanh
cng c)
Hoc chn biu tng View
Hoc chn Design View
Design View
IV. Thc hin truy vn
Form Report Macro
http://lnui.vn 58
V. Hiu chnh truy vn
Table Query M u
Trong ca s Database, chn tn truy vn, chn nt Design
m ca s thit k. Thc hin hiu chnh theo yu cu
nt Design
Form Report Macro
http://lnui.vn 59
VI. iu kin trong truy vn: khi thit k truy vn v thit lp
biu thc iu kin, c th s dng
Ton t ton hc
+, -, *, /, lu tha (^)
Thng s nguyn (chia ly phn nguyn): /
S d (chia ly phn d): Mod
Ton t logic
Not: cho kt qu ngc li (Not ng=sai, Not sai=ng)
And (v): cho kt qu ng khi tt c iu kin ng, nu mt
iu kin no sai th cho kt qu sai
Or (hoc): cho kt qu ng khi c t nht mt iu kin ng,
nu tt c iu kin sai th cho kt qu sai
Table Query M u Form Report Macro
http://lnui.vn 60
VI. iu kin trong truy vn
Ton t so snh
<, <=, >, >=, =, <>(khng bng)
Ton t so snh c bit
Between ... And ... (Nm trong khong)
Like (gn ging):
Vd: [slg] Between 150 And 200
(*) T hp bt k - Anh BanLike *B*
(?) K t bt k - AccessLike ???e*
(#) K s bt k - 2001 Like ##0#: True
Table Query M u Form Report Macro
http://lnui.vn 61
VI. iu kin trong truy vn
Ton t so snh c bit
Null , Not nul l: kim tra d liu c hay cha
Vd: tm cc th sinh thiu Ngy sinh, ta a gi tr Null
vo Criteria ca trng [Namsinh]
Table Query M u
Vd: tm cc khch hng c a ch, ta a gi tr Not
null vo Criteria ca trng [Diachi]
Form Report Macro
http://lnui.vn 62
VI. iu kin trong truy vn
Ton t ghp ni
& (ni chui)
& Nng: Nng
+(cng vi)
100 & nm c n: 100 nm c n
123 +456 : 579
Con thuyn+khng bn: Con thuyn khng bn
1001 +m: Type mismatch (kt qu sai)
123 & 456: 123456
Date() & Nhm Ng: 14/6/2002 Nhm Ng
V tuyn& 90/2 & ngy m: V tuyn 45 ngy m
Table Query M u Form Report Macro
http://lnui.vn 63
VI. iu kin trong truy vn
Hng tr (constants)
True/ False/ Null : hng tr ng/ sai/ rng
Du ro (Delimiter)
... : Ro gi tr chui
Vd: 43 Thanh Thu - Nng
[ ... ] : Ro tn bin
Vd: [SoLuong] * [DonGia]
#../../..#: Ro gi tr ngy
#23/04/2000#
Table Query M u Form Report Macro
http://lnui.vn 64
VI. iu kin trong truy vn
Table Query M u
iu kin cng tho mn/hoc tho mn
Cc iu kin vit cng trn dng Criteria l cc iu kin ng
thi tho mn
V d: tm cc khch loi phng L1Cv n trong thng
6, trn dng Criteria, ta ghi
iu kin ghi trn
cng 1 dng
Kt qu
Form Report Macro
http://lnui.vn 65
VI. iu kin trong truy vn
Table Query M u
Cc iu kin vit trn dng Criteria v dng Or l cc iu
kin khng cn ng thi tho mn
V d: tm cc khch loi phng L1Choc n trong
thng 6, trn dng Criteria v dng Or, ta ghi
Kt qu
iu kin ghi trn
dng Criteria v
dng Or
Form Report Macro
http://lnui.vn 66
VII. Mt s hm thng dng
Table Query M u
Hm x l chui
Hm LEFT, RIGHT
LEFT(Biu thc chui, n)
RIGHT(Biu thc chui, n)
Cng dng: tr v gi tr chui bng cch ly n k t bn tri
(LEFT) hoc bn phi (RIGHT) ca biu thc chui
V d: Trn dng Criteria ghi: RIGHT([Mahoadon],2)=NB:
tm cc chng t c 2 k t bn phi ca M ho n l
NB
Hm LEN(Biu thc chui)
Cng dng: tr v s l chiu di ca biu thc chui
V d: LEN(TRUNGTAM) cho kt qu l 8
Form Report Macro
http://lnui.vn 67
VII. Mt s hm thng dng
Table Query M u
Hm thi gian
Hm DATE( )
Cng dng: tr v ngy hin ti ca h thng
Hm DAY(Biu thc ngy)
Cng dng: tr v tr s l ngy/thng/nmca biu thc
ngy
Hm MONTH(Biu thc ngy)
Hm YEAR (Biu thc ngy)
V d: MONTH([Ngayden])=6: Tm cc khch n trong
thng 6
Form Report Macro
http://lnui.vn 68
VII. Mt s hm thng dng
Table Query M u
Hm logic
Hm IIF(iu kin, tr 1, tr 2)
Cng dng:
Nu iu kin tho mn, hm nhn tr 1
Nu iu ki n khng tho mn, hm nhn tr 2
V d: Ban hnh iu kin cho ct Xp loi nh sau
IIF([Diem]<5,Yu, IIF([Diem]<7,Trung bnh,
IIF([Diem]<8,Kh,Gii)))
Form Report Macro
http://lnui.vn 69
VIII. Mt s truy vn thng dng
Table Query M u
1. Truy vn cp nht (Update Query)
Cc bc xy dng truy vn cp nht
Chn ngun d liu (cc bng hoc truy vn khc)
Chn lnh Query / Update Query, hin thm hng Update to
trong li QBE
t biu thc vo Update
To ca trng cn sa
V d: trong hnh bn, khi
thc hin Query th n gi
mt hng Go s gim 1000
Criteria: ghi iu kin tng
ng
Form Report Macro
http://lnui.vn 70
VIII. Mt s truy vn thng dng
Table Query M u
2. Truy vn xo (Delete Query)
Chn ngun d liu (cc bng hoc truy vn khc)
Chn lnh Query / Delete Query, hin thm hng Delete trong
li QBE
Ko du * ca bng mun xo vo
dng Field, t kho From xut hin trn
dng Delete
Ko trng dng lp iu kin
vo dng Field, t kho Where xut
hin trn dng Delete
V d: trong hnh bn, khi thc hin
Query th cc mu tin c S ho n
l H01/KD s b xo
Form Report Macro
http://lnui.vn 71
1/Khi nim: Form l mt cng c ca Access dng th hin
v cp nht d liu cho cc bng, t chc giao din chng
trnh
Table
I. Gii thiu:
Chng IV : FORM (Mu biu)
M u Query
Khi c ngun d liu (Ngun t mt bng hoc mt truy vn):
Form dng th hin v cp nht d liu cho cc trng
ngun.
Khi khng c ngun d liu: Form dng t chc giao din
chng trnh
Form Report Macro
http://lnui.vn 72
Table M u
2.Cc thnh phn ca form:
Form header; Detail; Form Footer.
Caption: Tiu ca form.
Controls: lcc i tng iu khin trn form:
Text box, combo box, list box, command button,
option group....
Navigation Buttons: Nt cng c di chuyn qua cc
mu tin (First, Previous, Next, Last, New)
Query Form Report Macro
http://lnui.vn 73
Table M u
3/ Cc dng form:
1. Column Form: dng ct.
2. Tabular Form: dng danh sch.
3. J ustified: Dng hng.
4. DataSheet: dng d liu bng sheet.
5. Main Sub Form: Dng chnh ph.
gm 2 biu mu, mt biu mu chnh dng Column, cn
biu mu ph dng datasheet nm trong n. (Ch : biu
mu chnh l bng 1 cn biu mu ph l bng nhiu).
Query Form Report Macro
http://lnui.vn 74
Table M u
II. To Form
C th to bng nhiu cch khc nhau nh:
Form Wizard: to theo hng dn tng bc ca Access
AutoForm : t ng to theo cc kiu cho sn (Columnar /
Tabular / Datasheet)
Design View: T thit k theo mnh
Query Form Report Macro
http://lnui.vn 75
Table M u
1. Dng Auto Form:
To Form t ng vi tt c cc trng trong Table hoc Query.
Chn Forms / New, hp thoi New Form xut hin
Chn AutoForm:
Columnar
Chn OK kt qu s
xut hin
Chn ngun d liu
Query Form Report Macro
http://lnui.vn 76
Table M u
II. To Form
1. Dng Auto Form:
Mn hnh nhp liu nh sau
V mu tin u
tin
V mu tin pha
trc
Stt mu tin
hin ti
V mu tin
pha sau
Thm mu
tin mi
V mu tin
cui cng
Query Form Report Macro
http://lnui.vn 77
Table M u
More Controls
Line
Tab Control
Bound Object Frame
Image
List Box
Check Box
Toggle Button
Text Box
Controls Wizard
Rectangle
Subform/Subreport
Page Break
Unbound Object Frame
Command Button
Combo Box
Option Button
Option Group
Label
Select Object
Query Form Report Macro
http://lnui.vn 78
Table M u
to hnh ch nht Rectangle
to Form con, to Report con Subform/Subreport
to du phn trang Page Break
to mt khung hnh c nh
Unbound Obj ect Frame
to nt lnh Command Button
chn gi tr t danh sch Combo Box
to nt chn mt trong nhiu gi tr Option Button
nhm chn vic Option Group
to nhn Label
chn i tng cn hiu chnh Select Object
Query Form Report Macro
http://lnui.vn 79
Table M u
chn s dng cc nt iu khin t nhiu
chng trnh khc
More Controls
v ng thng Line
to Tab iu khin vic chn trang Tab Control
to khung hnh khng c nh
Bound Obj ect Frame
i tng hnh nh Image
hp danh sch, cho chn 1 gtr trong
danh sch
List Box
hp nh du chn nhiu ga tr cng
lc
Check Box
to nt bt tt Toggle Button
hin th gi tr/nhp d liu cho trng, kt
qu biu thc
Text Box
bt/tt Controls Wizard Controls Wizard
Query Form Report Macro
http://lnui.vn 80
Table M u
II. To Form
3. T thit k Form:
Kch vo cng c cn chn a vo Form
R chut ko Field cn chn vo trong Form
Khai bo cc thng tin cn thit. Nu mun sa i
cc thuc tnh th nhp p ti cng c va to khai
bo li
Query Form Report Macro
http://lnui.vn 81
Table M u
4. Thit k Form Chnh ph:
Bc 1: To biu mu chnh (Main)
D liu ngun (Record source): bng 1.
Dng hin th (Default View): Single Form
Bc 2: To biu mu ph (Sub)
D liu ngun (Record source): bng Nhiu
Dng hin th (Default View): DataSheet
Bc 3: Ko th biu mu Sub vo Main, lu quan h :
Link master field & Link child field
Khoquan h gia 2 bng.
Query Form Report Macro
http://lnui.vn 82
Table M u
II. To Form
3. Hiu chnh Form:
Trong ca s Database, chn tn Form cn hiu chnh, chn
nt Design
T sa i nh khi thit k
4. Thc hin Form
Trong ca s Database, chn tn Form cn thc hin, chn nt
Open
Query Form Report Macro
http://lnui.vn 83
Table M u
III. Cc loi iu khin
1. Cc loi iu khin
Khi thit k Form, thng dng cc loi iu khin sau:
Hp vn bn (Textbox)
Nhn (Label)
Hp la chn (Combo Box)
Hp danh sch (List Box)
Nt lnh (Command Button)
Nhm la chn (Option Group)
Query Form Report Macro
http://lnui.vn 84
Table M u
III. Cc loi iu khin
2. Cch dng
C th dng cc iu khin theo ba cch sau:
Bound (buc vi mt trng no ): ngun d liu ca n ly
t Table hay Query. Textbox l loi thng dng nht
Unbound (khng buc vo bt k trng no): khng mang d
liu ca bt k ngun no. Loi ny dng trnh by. Label l
loi thng dng nht
Calculated (tnh ton): ngun d liu l mt biu thc. Gi tr
hin th ch Form view l kt qu ca biu thc. Trong biu
thc c th dng kt hp cc php ton (+, -, *, /, =) vi cc
tn trng. Hm tr v gi tr hoc cc s. V d:
Giamoi:0.75*[Dongia]
Query Form Report Macro
http://lnui.vn 85
Table M u
III. Cc loi iu khin
3. Thay i trnh t thc hin cc iu khin
Khi chy Form, nu dng phm Tab hoc Shift+Tab th cc iu
khin s c chn theo trnh t thit k. Ta c th thay i bng
cch:
M Form ch Design.
Chn lnh View / Tab Order, xut hin hp thoi
Chn cc hng v ko r
chut thay i v tr
Query Form Report Macro
http://lnui.vn 86
Table M u
IV. Nt l nh Command Wizard
M Form ch Design.
Nhp chn biu tng Command Button v ko chut
trn Form ch nh v tr t nt lnh, xut hin hp i thoi
Command Button Wizard nh sau:
1. Cch to
Query Form Report Macro
M thanh Toolbox v kch hot nt Control Wizard
http://lnui.vn 87
Table M u
IV. Nt l nh Command Wizard
Categories: chn nhm lnh tu theo i tng
1
Actions: chn lnh c th
Chn Next sang bc tip theo, xut hin hp thoi
Query Form Report Macro
http://lnui.vn 88
Table M u
IV. Nt l nh Command Wizard
Text: Nhp tn chc nng ca nt lnh (nu mun)
Picture: chn hnh nh cho nt lnh (khng nhp tn)
Chn Next sang bc tip theo, xut hin hp thoi
2
Query Form Report Macro
http://lnui.vn 89
Table M u
IV. Nt l nh Command Wizard
t li tn cho nt, trnh trng vi tn chc nng (c th
mc nhin) ; Chn Finish hon thnh
3
Query Form Report Macro
http://lnui.vn 90
Table M u
IV. Nt l nh Command Wizard
Record Navigation (iu khin v tr mu ti n)
2. Danh sch cc Category v Act ion
Query Form
V mu tin pha trc Go to Previous Record
n mu tin tip theo Go to Next Record
V mu tin cui cng Go to Last Record
n mu tin u tin Go to First Record
M hp thoi tm mu tin Find Record
Tm n mu tin gn nht Find Next
Report Macro
http://lnui.vn 91
Table M u
IV. Nt l nh Command Wizard
Record Operations (Thao tc vi mu tin)
2. Danh sch cc Category v Act ion
Query Form
Phc hi mu tin Undo Record
Lu mu tin ang sa Save Record
In mu tin hin hnh Print Record
To mu tin mi trng vi mu tin
ang chn
Duplicate Record
Xo mu tin ang chn Delete Record
Thm mu tin mi Add New Record
Report Macro
http://lnui.vn 92
Table M u
IV. Nt l nh Command Wizard
Form Operations (Thao tc vi Form)
2. Danh sch cc Category v Act ion
Query Form
Lm mi li d liu trong Form Refresh Form Data
In Form hin hnh Print Current Form
In Form Print a Form
M Form Open Form
ng Form Close Form
To tiu chun lc Edit Form Filter
p dng lc mu tin vi tiu chun
va to
Apply Form Fi lter
Report Macro
http://lnui.vn 93
Table M u
IV. Nt l nh Command Wizard
Report Operations (Thao tc vi Report)
2. Danh sch cc Category v Act ion
Query Form
Chuyn Report thnh mt tp tin Send Report to File
In Report ra giy Print Report
Xem Report trc khi in Preview Report
Gi Email Report Mail Report
Report Macro
http://lnui.vn 94
Table M u Report
IV. Nt l nh Command Wizard
2. Danh sch cc Category v Act ion
Query Form
Appl ication (Thao tc vi ng dng)
Chy ng dng Run Appl ication
Thot ng dng Quit Application
Micellaneous (Thao tc vi cc i tng khc)
Thc hin mt Query Run Query
Chy mt Macro Run Macro
In bng Print Table
Macro
http://lnui.vn 95
Report l mt cng c thun tin in d liu. Ngun d liu
ca Report l cc Table c sn hoc s liu c tng hp di
dng Query
Table
I. Khi nim
Chng V : Report (Bo co-Bo biu)
M u Query Report Form
II. Cc ki u trnh by Report
Columnar Report (bo biu dng ct)
Tabular Report (bo biu dng bng)
Macro
http://lnui.vn 96
Table M u Query Report Form
II. Cc ki u trnh by Report
1. Col umnar Report
(bo biu dng ct)
L dng thc m cc trng
s liu trong Report c trnh
by t trn xung thnh mt
ct.
Macro
http://lnui.vn 97
Table M u Query Report Form
II. Cc ki u trnh by Report
2. Tabular Report (bo biu dng bng)
Mi Record th hin trn mt dng, cc trng c xp
thnh ct. Loi ny thch hp cho bng k s liu
Macro
http://lnui.vn 98
Table M u Query Report Form
III. Cch to Report
Ti ca s Database, chn Report / New, xut hin ca s
New Report
Chn cch to
Report
Chn ngun s liu
to Report
Chn mt trong cc cch to Report, n gin, ta chn
Report Wizard.
Chn ngun s liu
to Report (Table
hay Query tu theo
yu cu c th)
Chn OK, xut hin
hp thoi Report
Wizard (a) nh sau
Macro
http://lnui.vn 99
Table M u Query Report Form
III. Cch to Report
Available Fields: cha cc trng c sn trong ngun
1a
1b
Chn cc trng ph
hp v a sang mc
Selected Fields (b)
Chn Next sang
bc tip theo,
xut hin hp
thoi
Macro
http://lnui.vn 100
Table M u Query Report Form
III. Cch to Report
Hp thoi ny hi bn mun hin th d liu t u, bn tu
chn cho ph hp
2
Chn Next sang
bc tip theo,
xut hin hp
thoi
2
Macro
http://lnui.vn 101
Table M u Query Report Form
III. Cch to Report
Cho chn trng cn kt nhm (nu mun), bn tu chn cho
ph hp
3
Chn Next sang bc tip theo, xut hin hp thoi
Macro
http://lnui.vn 102
Table M u Query Report Form
III. Cch to Report
Cho chn cc trng m danh sch s sp xp theo th t u
tin, s kho sp xp ti a l bn.
Chn Summary Options nu mun tnh ton, xut hin hp
thoi
4
Sp xp theo
bn kho tu
Sp xp theo
th t tng hoc
gim dn
Macro
http://lnui.vn 103
Table M u Query Report Form
III. Cch to Report
Chn cc trng cn tnh ton, kiu tnh (Sum, Avg, Min,
Max)
Show: chn cch hin th: chi tit v tng (Detail and
Summary) hay ch hin tng (Summary Only)
Chn trng
cn tnh ton
Chn hm cn
tnh
5
Calculate percent of total for sums: chn nu mun tnh % trn
tng s
Chn OK, quay v hp thoi . Ti hp thoi , chn Next
sang bc tip theo, xut hin hp thoi
Macro
http://lnui.vn 104
Table M u Query Report Form
III. Cch to Report
Layout: chn kiu trnh by
Chn Next sang bc tip theo, xut hin hp thoi
Orientation: chn hng in ca trang giy
6
Kiu trnh by
Hng in ca giy
Macro
http://lnui.vn 105
Table M u Query Report Form
III. Cch to Report
Chn mt trong cc mu trnh by
Chn Next sang bc tip theo, xut hin hp thoi
7 Danh sch cc mu
Macro
http://lnui.vn 106
Table M u Query Report Form
III. Cch to Report
t tn cho Report
Chn Finish hon thnh, kt qu s xut hin
8
G tn Report
vo y
C th m ca s Design trnh by thm nu mun
Macro
http://lnui.vn 107
Table M u Macro Query Report Form
III. Cch to Report
Thm S th t
K khung
Cc tnh ton cn thit
http://lnui.vn 108
Chcquv thnhcng
C s Tin hc Xun Nui
in thoi: (068)3.854.854 - 0121.23.23.555
Website: lnui.vn