115
រមក សពៃថេនះ រេបស់កុំព ទ័រ គឺមេធយ៉ ងសំន់មួយ ក ងរេះយប និងជួយសំរួលដល់រ រ បំៃថរបស់មនុសែដលរស់េេលពិភពេក។ គេចនររ េសរែតំងអស់របស់ពួកេគគឺពឹងែផកេ លរ េបស់កុំព ទ័រំងសង ែដលេហតុមរឲអកេបស់តវនសមតព និងចំេនះដឹងគប់ន់ ងរ េបស់េេល។ ដមីចូលរួមេលកស យវិស័យព័ត៌នវិទ េក ងពះចកកម មជមណ លព័ត៌នវិទ អិនធ័រ តវន បេងតេឡងផងែដរ ក ងេលបំនង េដមីជួយបណ លចំេនះដឹងែផកព័ត៌នវិទដល់ សិស និសិត និងអក សិក ឲនចំេនះដឹងពិតកដក ងែផកេនះ ពិេសសនសមតពចស់ស់ក ងរេបស់កុំព ទ័រ។ ដូចេនះសូម សិស និសិត និងអកសិកំងអស់ ខិតខំបឹងែបង សិក វវ និងប់យកនូវចំេនះដឹង ែដល មជមណល នបណ លជូន េដមីឲេពលេវែដលអកនចំយ យេបេជន៍មួយ៉ ងធំេធង សំប់ជីវិតរបស់អកេពលអគត។ យងខ ដលអកេរបេរងៃន មជមណ លព័ត៌នវិទ អិនធ័រ សូមអរគុណចំេះរំទរបស់ សិស និសិត និងអកសិកំងអស់ និងសូមអភ័យ េសល់កំហុសឆងែដលេកតនក ងករណី មួយ េហយេយងខ នឹងខិត ខំ រិះរកនូវអីែដលថីក ងែផកព័ត៌នវិទេនះ េដមីផល់ជូនដល់ អកសិកបែនមេទត សូមអរគុណ និងសូម ជំបសួរ ។ កមអកេរបេរងៃន មជមណលព័ត៌នវិទ អិនធ័រ

Advance Access 2010 Khmer

Embed Size (px)

DESCRIPTION

Advance Access 2010 Khmer

Citation preview

Page 1: Advance Access 2010 Khmer

�រម�ក�

សព�ៃថ�េនះ �រេ ប �សក់ុំព�ូទ័រ គឺ�មេធ��យ!៉ងស$ំន់មួយ ក&ុង�រេ'ះ (យប)* និងជួយសរំលួដល�់រ

/រ ប0ំៃថ�របសម់នុស1ែដលរសេ់3េលពិភពេ5ក។ 7គេ ចន�រ/រ េស9រែត;ំងអសរ់បសព់ួកេគគឺពឹងែផ?កេ@

េល�រ េ ប �សក់ុំព�ូទ័រ;ំង សAង ែដល�េហតុ;ម;រឲអ&កេ ប �ស ់តDវFនសមតG7ព និងចំេនះដឹង គប់ Hន់

ក&ុង�រ េ ប �សេ់@េលI។

េដមJីចូលរួមេលកស9ួយវសិយ័ព័ត៌Fនវទិ� េ3ក&ុង ពះM�Nច កកមOុ� មជPមណR លព័ត៌Fនវទិ� អិនធ័រ តDវ�ន

បេងSតេឡងផងែដរ ក&ុងេHលបំនង េដមJីជួយបណUុ ះបNU លចំេនះដឹងែផ&កព័ត៌Fនវទិ�ដល ់សសិ1 និស1ិត និងអ&ក

សកិV ឲFនចំេនះដឹងពិត �កដក&ុងែផ&កេនះ �ពិេសសFនសមតG7ពចWស5់សក់&ុង�រេ ប �សក់ុំព�ូទ័រ។

ដូចេនះសមូ សសិ1 និស1ិត និងអ&កសកិV;ំងអស ់ខិតខំ បឹងែ បង សកិV (វ �វ និង0ប់យកនូវចំេនះដឹង ែដល

មជPមណR ល �នបណUុ ះបNU លជូន េដមJីឲេពលេវ5ែដលអ&ក�នចំYយ �Z យេ@� បេ!ជន៍មួយ!៉ងធំេធង

សMំប់ជីវតិរបសអ់&កYេពលអYគត។

េយងខ\ុ ំែដល�អ&កេរ]បេរ]ងៃន មជPមណR លព័ត៌Fនវទិ� អិនធ័រ សមូអរគុណចំេ^ះ�រHំ ទរបស ់សសិ1 និស1ិត

និងអ&កសកិV;ំងអស ់និងសមូអភ័យ េ;សMលក់ំហសុឆ`ងែដលេកតFនក&ុងករណីNមួយ េហយេយងខ\ុ ំ នឹងខិត

ខំ រះិរកនូវអ�ីែដលថaីក&ុងែផ&កព័ត៌Fនវទិ�េនះ េដមJីផUលជ់ូនដល ់អ&កសកិVបែនGមេទ]ត សមូអរគុណ និងសមូ

ជំMបសរួ ។

កAមអ&កេរ]បេរ]ងៃន

មជPមណR លព័ត៌Fនវទិ� អិនធ័រ

Page 2: Advance Access 2010 Khmer

�កមអ�កេរ បេរ ង អ�កេរ បេរ ង:

ហ ូម៉ូន&ី

អ�ករច�គំរប:

ហ ូម៉ូន&ី

អ�ក�យអត�បទ ន�ងេរ បចំរបូ�ព:

ហ ូម៉ូន&ី

ច័ន9cរទិd

អ�កែកសំរលួអក#$%រទុ':

ហ ូម៉ូន&ី

ច័ន9cរទិd

តិល ភកUី

ចិន សវុណe

េរ បេរ ងេល(កទ( ២: រកVសទិd គប់!៉ង © 2013 េ'យ មជPមណR លព័ត៌Fនវទិ� អិនធ័រ សMំប់� ឯក(រេ ប �សៃ់ផ9ក&ុង។

Ha នែផ&កNមួយៃនេស]វេkេនះ តDវ�ន ផលតិេឡងវញិ េ;ះ�មេធ��យNកេ៏'យ េ3េពលែដលHa ន�រ

អនុ)n តិ�5យលកoណ៍អក1រ ពីFp សក់មaសទិd។

�សយ*+ ន: ផ9ះេលខ 179 ផZូ វ 173 ស/S ត់ ទំនប់ទឹក ខណR ចំ�រមន Mជcនីភ&ំេពញ

Tel: 010-011-012-016 603 314

Website: www.enteritc.com | facebook.com/enteritc

Page 3: Advance Access 2010 Khmer

,-. េមេរ]នទី 1: �រែណYំឲ(̀លព់ី SQL Statement .............................................................................................................................. 1

េមេរ]នទី 2: មូល'� ន គឹះៃន�រេ ប �ស ់Macro ........................................................................................................................... 19

េមេរ]នទី 3: �រសកិVពី VBA.................................................................................................................................................................. 37

េមេរ]នទី 4: សកិVលអំិតពី VBA ............................................................................................................................................................ 57

េមេរ]នទី 5: �រែណYំពី DAO ................................................................................................................................................................ 71

េមេរ]នទី 6: �រ7� ប់ ComboBox & ListBox �មួយ DAO ............................................................................................................... 85

េមេរ]នទី 7: �រេ ប �ស ់Keyword Execute ក&ុង DAO ................................................................................................................ 97

េមេរ]នទី 8: �របេងSតកមaវធិី គប់ គង Stock ................................................................................................................................. 103

េមេរ]នទី 9: រេប]ប search ទិន&ន័យេ3ក&ុង Stock .......................................................................................................................... 111

Page 4: Advance Access 2010 Khmer
Page 5: Advance Access 2010 Khmer

Access 2010 Advance www.enteritc.com 1

មជ0មណ2 លពត័,៌ន%ទ5អ�នធរ័ Enter Information Technology Center

េមេរ នទ( 1: .រែណ�ំឲ89 លព់( SQL Statement (Structure Query Language)

1. ន�យមនយ័:

SQL គឺ�7(មួយែដល តDវ�នេ ប �សេ់ដមJី សង់ទិន&ន័យេ@ មលកoខណR ែដល តDវ�រ េ'យFនលកoណៈ ដូច

Query ែដរដូច� ¢ចេធ��រ ប£pូ លទិន&ន័យ, ែកសរំលួទិន&ន័យ, ឬលបុទិន&ន័យ�េដម។ បុ៉ែនUI សង់ទិន&ន័យេ'យ

េធ��រសរេសរ command ខុសពី Query សង់ទិន&ន័យេ'យេ ប �ស ់Wizard ។

I�7(មួយែដលFន (ប់េ3ក&ុង Database Engines �េ ចន Fនន័យ¨េយង¢ចយក SQL Language េ@

Apply េ3ក&ុង Database YY ដូច� Microsoft Access, Microsoft SQL Server, ឬ Oracle �េដមេហយចំេ^ះ

Microsoft Access វញិគឺេយង តDវ សរេសរ SQL េ3ក&ុង Query Object ផងែដរ។

2. រេប បសរេសរ SQL Statement:

1. ចុច Create Tab >

2. Query Design >

3. Close Button >

Page 6: Advance Access 2010 Khmer

2 www.enteritc.com Microsoft Access 2010 Advance

Enter Information Technology Center មជ0មណ2 លពត័,៌ន%ទ5អ�នធរ័

4. ចុច View Arrow >

5. SQL View >

6. ក&ុងតំបន់ Query សមូសរេសរកូដដូច$ងេ �ម >

7. ចុច Run >

8. $ងេ �មេនះ�លទdផលែដលទទួល�ន

select StudentID,FullName,Gender,Class

from TableStudentList

where StudentID > 4

order by FullName ASC;

Page 7: Advance Access 2010 Khmer

Access 2010 Advance www.enteritc.com 3

មជ0មណ2 លពត័,៌ន%ទ5អ�នធរ័ Enter Information Technology Center

3. .រេ�>(�?ស ់Select Statement:

Select Statement គឺ� SQL Statement ែដលេ បេដមJី Select យកទិន&ន័យពី Table េ@ មលកoខណR ែដល តDវ �រ។

Syntax:

Example: ឧ;ហរណ៍$ងេ �មនឹងប/* ញពី�រេ ប �ស ់Select Statement េ'យ:

> សង់យក StudentID, FullName, Gender, និង Class

> េចញពី TableStudentList

> េហយ សង់យក StudentID ;ំង´យNែដលធំ�ង 4

> តំេរ]បទិន&ន័យែដល តDវប/* ញ មល'ំប់េកន ។

SQL Statement:

Output:

select StudentID,FullName,Gender,Class

from TableStudentList

where StudentID > 4

order by FullName ASC;

Select <FieldName1,[FieldName2,]>

from <TableName>

Where <Condition>

Order By <FieldName> ASC|DESC;

Page 8: Advance Access 2010 Khmer

4 www.enteritc.com Microsoft Access 2010 Advance

Enter Information Technology Center មជ0មណ2 លពត័,៌ន%ទ5អ�នធរ័

4. .រេ�>(�?ស ់Select Top Statement:

Select Top Statement គឺ� SQL Statement ែដលេ បេដមJី Select យកទិន&ន័យពី Table េ@ មលកoខណR ែដល

និងចំនួន Records ែដល តDវ�រ។

Syntax:

Example: ឧ;ហរណ៍$ងេ �មនឹងប/* ញពី�រេ ប �ស ់Select Statement េ'យ:

> សង់យក StudentID, FullName, Gender, និង Class ចំនួនែត 2 records

> េចញពី TableStudentList

> េហយ សង់យក StudentID ;ំង´យNែដលធំ�ង 4

> តំេរ]បទិន&ន័យែដល តDវប/* ញ មល'ំប់េកន ។

SQL Statement:

Output:

Select <Top Number> <FieldName1,[FieldName2,]>

from <TableName>

Where <Condition>

Order By <FieldName> ASC|DESC;

select Top 2 StudentID,FullName,Gender,Class

from TableStudentList

where StudentID > 4

order by FullName ASC;

Page 9: Advance Access 2010 Khmer

Access 2010 Advance www.enteritc.com 5

មជ0មណ2 លពត័,៌ន%ទ5អ�នធរ័ Enter Information Technology Center

5. .រេ�>(�?ស ់Select and Join On Statement:

Select and Join On Statement គឺ� SQL Statement ែដលេ បេដមJី Select យកទិន&ន័យពី Table ពីរឬេ ចនែដល Fន

Relationship �មួយH& េ'យក&ុងេYះIែផ?កេ@េលលកoខណR 3 ែដល តDវកំនត់:

> Select Inner Join: គឺ សង់យក Record របស ់Primary Table ែដលFន Relationship �មួយ Record របស ់

Related Table ែតប៉ុេNe ះ។

> Select Left Join : សង់យក Record របស ់Primary Table ;ំងអស�់មួយ Record របស ់Related Table

ែដលFន Relationship �មួយH& ែតប៉ុេNe ះ។

> Select Right Join: សង់យក Record របស ់Primary Table មួយចំនួនែដលFន Relationship �មួយនឹង

Record របស ់Related Table ែតប៉ុេNe ះ។

6. .រេ�>(�?ស ់Select Inner Join: Example: ឧ;ហរណ៍$ងេ �មនឹងប/* ញពី�រ សង់យកទិន&ន័យមួយចំនួនដូច� StudentID, FullName, Gender េចញពី

TableStudentList និង Points េចញពី TableStudyList េហយ សង់យក StudentID ែដលធំ�ង 4 ។

SQL Statement:

Output:

Select TableStudentList.StudentID,FullName,

Gender, Points

From TableStudentList Inner join TableStudyList

On TableStudentList.StudentID =

TableStudyList.StudentID

Where TableStudentList.StudentID > 4

Order by FullName;

Page 10: Advance Access 2010 Khmer

6 www.enteritc.com Microsoft Access 2010 Advance

Enter Information Technology Center មជ0មណ2 លពត័,៌ន%ទ5អ�នធរ័

7. .រេ�>(�?ស ់Select Left Join:

Example: ឧ;ហរណ៍$ងេ �មនឹងប/* ញពី�រ សង់យកទិន&ន័យមួយចំនួនដូច� StudentID, FullName, Gender េចញពី

TableStudentList និង Points េចញពី TableStudyList េហយ សង់យក StudentID ែដលធំ�ង 4 ។

SQL Statement:

Select TableStudentList.StudentID,FullName,

Gender, Points

From TableStudentList Left join TableStudyList

On TableStudentList.StudentID =

TableStudyList.StudentID

Where TableStudentList.StudentID > 4

Order by FullName;

Page 11: Advance Access 2010 Khmer

Access 2010 Advance www.enteritc.com 7

មជ0មណ2 លពត័,៌ន%ទ5អ�នធរ័ Enter Information Technology Center

Output:

8. .រេ�>(�?ស ់Select Left Join:

Example: ឧ;ហរណ៍$ងេ �មនឹងប/* ញពី�រ សង់យកទិន&ន័យមួយចំនួនដូច� StudentID, FullName, Gender េចញពី

TableStudentList និង Points េចញពី TableStudyList េហយ សង់យក StudentID ែដលធំ�ង 4 ។

SQL Statement:

Select TableStudentList.StudentID,FullName,

Gender, Points

From TableStudentList Right join TableStudyList

On TableStudentList.StudentID =

TableStudyList.StudentID

Where TableStudentList.StudentID > 4

Order by FullName;

Page 12: Advance Access 2010 Khmer

8 www.enteritc.com Microsoft Access 2010 Advance

Enter Information Technology Center មជ0មណ2 លពត័,៌ន%ទ5អ�នធរ័

Output:

9. .រេ�>(�?ស ់Aggregation Function:

Aggregation Function គឺ��រសរេសរកូដ SQL Statement េ'យ7� ប់�មួយនឹង�រគណYមួយចំនួន េ@ ម

តំរវូ�រ។ េយង¢ចេធ��រគណYេ'យ·9 លក់�៏ន ឬក¢៏ចេ ប �ស ់Function មួយចំនួនែដលFន (ប់ដូច�:

> Sum(Field)

> Avg(Field)

> Count(Field)

> Max(Field)

> Min(Field)

រេប បទ( 1:

ឧ;ហរណ៍$ងេ �មនឹងប/* ញពី�រ សង់យកទិន&ន័យមួយចំនួនដូច� StudentID, FullName, Gender េចញពី

TableStudentList និង Points េចញពី StudentList និងTableStudyList េ'យបែនGម Field ពីរែដលក&ុង េYះ Field ទី 1

គឺេºa ះ Total ផ9ុកទិន&ន័យ សរបុរបសព់ិន9ុសសិ1 និង Field ទី 2 គឺេºa ះ Average ផ9ុកទិន&ន័យមធ�មរបសព់ិន9ុ

សសិ1។ បY9 ប់មកនឹងេធ��រ សង់យក StudentID ែដលធំ�ង 5 ែតប៉ុេNe ះ ។

Page 13: Advance Access 2010 Khmer

Access 2010 Advance www.enteritc.com 9

មជ0មណ2 លពត័,៌ន%ទ5អ�នធរ័ Enter Information Technology Center

SQL Statement:

Output:

រេប បទ( 2: SQL Statement:

SELECT TableStudentList.StudentID, FullName, Gender,

Class,

Sum(Points) AS Total, Avg(Points) AS Average

FROM TableStudentList INNER JOIN TableStudyList ON

TableStudentList.StudentID = TableStudyList.StudentID

GROUP BY TableStudentList.StudentID, FullName, Gender,

Class

HAVING TableStudentList.StudentID>5

ORDER BY FullName;

SELECT TableStudentList.StudentID, FullName, Gender,

Class, Sum(Points) AS Total,

Format(Avg(Points),"00.00") AS Average

FROM TableStudentList INNER JOIN TableStudyList ON

TableStudentList.StudentID = TableStudyList.StudentID

Where TableStudentList.StudentID>5

GROUP BY TableStudentList.StudentID, FullName, Gender,

Class

ORDER BY FullName;

Page 14: Advance Access 2010 Khmer

10 www.enteritc.com Microsoft Access 2010 Advance

Enter Information Technology Center មជ0មណ2 លពត័,៌ន%ទ5អ�នធរ័

10. .រេ�>(�?ស ់iif ក�ុង Aggregation Function: Example: ឧ;ហរណ៍$ងេ �មបនUពីឧ;ហរណ៍មុន នឹងប/* ញពី�របេងSត�រគណY�មួយនឹង iif េ'យបេងSត� Field ថaី

ចំនួន 2 េទ]តែដលទី 1 េºa ះ Result ប/* ញ¨ បសនិេប Average 0ប់ពី 5 េឡងេ@ Pass ែតេប;ប�ង Fail ។

ចំែនក Field ទី 2 េºa ះ Mention ប/* ញ¨ បសនិេប:

> Average 0ប់ពី 9 េឡងេ@ប/* ញ A

> Average 0ប់ពី 8 េឡងេ@ប/* ញ B

> Average 0ប់ពី 7 េឡងេ@ប/* ញ C

> Average 0ប់ពី 6 េឡងេ@ប/* ញ D

> Average 0ប់ពី 5 េឡងេ@ប/* ញ E

> Average ;ប�ង 5 ប/* ញ F

SQL Statement:

Output:

SELECT TableStudentList.StudentID, FullName, Gender,

Class, sum(Points) AS Total, avg(Points) AS Average

,iif(Average>=5,"Pass","Fail") As Result,

iif(Average>=9,"A",iif(Average>=8,"B",iif(Average>=7,"C

",iif(Average>=6,"D",iif(Average>=5,"E","F"))))) As

Mention

FROM TableStudentList INNER JOIN TableStudyList ON

TableStudentList.StudentID = TableStudyList.StudentID

GROUP BY TableStudentList.StudentID, FullName, Gender,

Class

HAVING TableStudentList.StudentID>5

ORDER BY FullName;

Page 15: Advance Access 2010 Khmer

Access 2010 Advance www.enteritc.com 11

មជ0មណ2 លពត័,៌ន%ទ5អ�នធរ័ Enter Information Technology Center

11. .រេ�>(�?ស ់SQL Statement េដAមB(បេងC(ត Crosstab Query: SQL Statement:

Output:

12. .រេ�>(�?ស ់Insert Statement:

Insert Statement គឺ� SQL Statement ែដលេ បេដមJីប£pូ លយកទិន&ន័យេ@ក&ុង Table េ@ មលកoខណR ែដល តDវ

�រ។

Syntax:

Example: ឧ;ហរណ៍$ងេ �មនឹងប/* ញពី�រេ ប �ស ់Insert Statement េ'យ:

> តង់ Field StudentID ប£pូ ល 20

> FullName ប£pូ ល Chea Phalla

> Gender ប£pូ ល 'Female'

> និង Class ប£pូ ល '10E' ។

Transform Sum(Points) As TotalPoint

Select TableStudentList.StudentID,FullName, Gender,

Class,Sum(Points) As Total

FROM TableStudentList INNER JOIN TableStudyList ON

TableStudentList.StudentID = TableStudyList.StudentID

Where TableStudentList.StudentID > 5

Group By

TableStudentList.StudentID,FullName,Gender,Class

Order By FullName

Pivot SubjectID;

Insert Into <TableName>

Value <Values>

Page 16: Advance Access 2010 Khmer

12 www.enteritc.com Microsoft Access 2010 Advance

Enter Information Technology Center មជ0មណ2 លពត័,៌ន%ទ5អ�នធរ័

SQL Statement:

Output:

13. .រេ�>(�?ស ់Update Statement:

Update Statement គឺ� SQL Statement ែដលេ បេដមJីែកែ បទិន&ន័យេ@ក&ុង Table េ@ មលកoខណR ែដល តDវ �រ។

Syntax:

Example: ឧ;ហរណ៍$ងេ �មនឹងប/* ញពី�រេ ប �ស ់Insert Statement េ'យ:

> តង់ Field StudentID ប£pូ ល 20

> FullName ប£pូ ល Chea Phalla

> Gender ប£pូ ល 'Female'

> និង Class ប£pូ ល '10E' ។

Insert Into TableStudentList(StudentID,FullName,Gender,Class)

Values(20,'Chea Phalla','Female','10E')

Update <TableName>

Set <FieldName> = <value>

Where condition

Page 17: Advance Access 2010 Khmer

Access 2010 Advance www.enteritc.com 13

មជ0មណ2 លពត័,៌ន%ទ5អ�នធរ័ Enter Information Technology Center

SQL Statement:

Output:

14. រេប ប�សងទ់�ន�នយ័ព( Table មយួេD*ក ់Table មយួេទ ត: Example: ឧ;ហរណ៍$ងេ �មនឹងប/* ញពី�រ សង់យកទិន&ន័យ0ប់ពី Record ទី 6 េឡងេ@ែដលFនដូច� StudentID,

FullName, Gender, Class េចញពី TableStudentList េ@'ក់េ3ក&ុង Table េផ1ងមួយេទ]តែដល�នបេងSតេហយ

គឺេºa ះ TableStudentList2 ។

SQL Statement:

Output:

15. រេប ប�សងទ់�ន�នយ័ព( Table មយួេDបេងC(តE Table ថGAមយួេទ ត: Example: ឧ;ហរណ៍$ងេ �មនឹងប/* ញពី�រ សង់យកទិន&ន័យ0ប់ពី Record ទី 6 េឡងេ@ែដលFនដូច� StudentID,

FullName, Gender, Class េចញពី TableStudentList េ@'ក់េ3ក&ុង Table ថaីមួយេទ]ត គឺេºa ះ TableStudentList3

ែដល តDវ�នបេងSតេ'យេ ប �ស�់មួយនឹង SQL Statement ។

UPDATE TableStudentList

SET StudentID = 15, FullName = 'Lim Kevtheara',

Class = '10B'

WHERE StudentID =20;

Insert Into TableStudentList2(StudentID,FullName,Gender,Class)

Select StudentID,FullName,Gender,Class

From TableStudentList Where StudentID > 5

Page 18: Advance Access 2010 Khmer

14 www.enteritc.com Microsoft Access 2010 Advance

Enter Information Technology Center មជ0មណ2 លពត័,៌ន%ទ5អ�នធរ័

SQL Statement:

Output:

16. រេប បបេងC(ត Table: SQL Statement:

Output:

17. រេប បបែន�ម Field ឲ Table:

Syntax:

Example: ឧ;ហរណ៍$ងេ �មនឹងប/* ញពី�របែនGម Field ចំនួន 2 េ@ឲ TableStudentList2 ែដល Field ទី 1 េºa ះ

PhoneNumber Fន DataType � Text និង Field ទី 2 េºa ះ Payment Fន DataType � Currency ។

Select StudentID, FullName, Gender, Class Into TableStudentList3

From TableStudentList2

Where StudentID >5

CREATE TABLE Student ( StudentID int PRIMARY KEY, Name CHAR(255), Course CHAR(255), Marks INTEGER, Grade CHAR(255), Phone INTEGER, Present YESNO );

Alter Table <TableName>

Add Column <FieldName DataType>

Page 19: Advance Access 2010 Khmer

Access 2010 Advance www.enteritc.com 15

មជ0មណ2 លពត័,៌ន%ទ5អ�នធរ័ Enter Information Technology Center

SQL Statement:

18. រេប បលបុ Field េចញព( Table:

Syntax:

Example: ឧ;ហរណ៍$ងេ �មនឹងប/* ញពី�រលបុ Field ចំនួន 2 េចញពី TableStudentList2 ែដល Field ទី 1 េºa ះ

PhoneNumber និង Field ទី 2 េºa ះ Payment ។ SQL Statement:

19. រេប បលបុ Record េចញព( Table: Syntax:

Example: ឧ;ហរណ៍$ងេ �មនឹងប/* ញពី�រលបុ Record របស ់StudentID េលខ 15 េចញពី TableStudentList ។

SQL Statement:

Alter Table TableStudentList2

Add Column PhoneNumber Text(20), Payment Single

Alter Table TableStudentList2

Drop Column PhoneNumber, Payment

Alter Table <TableName>

Drop Column <FieldName>

Delete from TableStudentList

Where StudentID = 15

Delete from <TableName>

Where <condition>

Page 20: Advance Access 2010 Khmer

16 www.enteritc.com Microsoft Access 2010 Advance

Enter Information Technology Center មជ0មណ2 លពត័,៌ន%ទ5អ�នធរ័

Output:

20. រេប បលបុ Table:

Example: ឧ;ហរណ៍$ងេ �មនឹងប/* ញពី�រលបុ TableStudentList2 េចញពី Database ។

SQL Statement:

21. .រេ�>(�?ស ់Union:

Union គឺ តDវ�នេ ប �សេ់ដមJីេធ��រ Select យក Record �េ ចនេចញពី Table �េ ចនេផ1ងៗH& ផងែដរ។ Example: ឧ;ហរណ៍$ងេ �មនឹងប/* ញពី�រលបុ TableStudentList2 េចញពី Database ។

SQL Statement:

Output:

Drop Table TableStudentList2

Select StudentID,FullName,Gender,Class From [TableStudentList1-5]

Union

Select StudentID,FullName,Gender,Class From [TableStudentList6-12]

Page 21: Advance Access 2010 Khmer

Access 2010 Advance www.enteritc.com 17

មជ0មណ2 លពត័,៌ន%ទ5អ�នធរ័ Enter Information Technology Center

22. .រេ�>(�?ស ់Sub Query:

Sub Query គឺ��រសរេសរ SQL Statement េដមJី សង់ទិន&ន័យេ@ មលកoខណR ែដល�លទdផលៃន Query មួយ

េផ1ងេទ]ត។

Syntax: SQL Statement:

Output:

Select StudentID,FullName,Gender,Class From TableStudentList

Where StudentID in (

Select StudentID from TableStudentList

where StudentID=5);

Select <FieldNameI> From <TableNameI>

Where <ConditionI> IN|NOT IN (

Select <FieldNameII> from <TableNameII>

where <ConditionII> );

Page 22: Advance Access 2010 Khmer

18 www.enteritc.com Microsoft Access 2010 Advance

Enter Information Technology Center មជ0មណ2 លពត័,៌ន%ទ5អ�នធរ័

Page 23: Advance Access 2010 Khmer

Access 2010 Advance www.enteritc.com 19

មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័ Enter Information Technology Center

េមេរ�នទ� 2: មលូ�� ន��ះៃន�រ

េ�!��"ស ់Macro

1. ន�យមនយ័:

Macro គឺ� Object មួយេក�ុង Microsoft Access ែដល�នតួ�ទីបេង�នេល��ន�រ�រេក�ុង Database របសេយង

េ!យ"ចបេង�ត� Button ឬ Menu ស&ំប់ចងប()ូ ល+� េេល Form ស&ំប់េ,ប,-ស.់/ លេ់ល�រ�ររបសេ់យង។

1មឧ3ហរណ៍7ងេ,�ម នឹងប�9 ញពី�របេង�ត Macro មួយេ<= ះ Autoexe េដម�ីដំេន�រចូលេ?េបក

FormMainboardButton េ!យស@យ័,បវតGិេេពលែដលេយងេបក Database ។

1. សមូបេង�ត FormMainboardButton េ!យចុច Create Tab >

2. Form Design >

3. ចុច Save Button េហយ!ក់េ<= ះQR FormMainboardButton ប�/ ប់មកបិទ./ ំងQេUល >

4. ចុច Create Tab >

5. Macro >

6. ក�ុង,បអប់ Add New Action សមូេ,ជសេរ សយក OpenForm >

Page 24: Advance Access 2010 Khmer

20 www.enteritc.com Microsoft Access 2010 Advance

Enter Information Technology Center មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័

7. ក�ុង,បអប់ Form Name សមូកំនត់េ<= ះ Form ,ត]វេធ@�រ គឺ FormMainboardButton >

8. ក�ុង,បអប់ View េ,ជសេរ សយក Form >

9. ក�ុង,បអប់ Data Mode េ,ជសេរ សយក Edit >

10. ក�ុង,បអប់ Window Mode េ,ជសេរ សយក Normal >

11. ចុច Save Button េហយក�ុង,បអប់ Macro Name សមូកំនត់ MacroAutoexe >

12. ចុច OK Button >

13. ចុច Run Button េដម�ីេមលលទ|ផល

Page 25: Advance Access 2010 Khmer

Access 2010 Advance www.enteritc.com 21

មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័ Enter Information Technology Center

2. �របេង(�ត Open Button:

1មឧ3ហរណ៍7ងេ,�មគឺ�បេង�ត Macro មួយេ<= ះ OpenTableStudentList េ!យឲQេធ@�រេបកនូវ

TableStudentList ។

1. ចុច Create Tab >

2. ចុច Macro >

3. ក�ុង,បអប់ Add New Action េ,ជសេរ សយក CloseWindow >

4. ក�ុង,បអប់ Table Name សមូកំនត់េ<= ះ Table ,ត]វេធ@�រ គឺ TableStudentList >

5. ក�ុង,បអប់ View េ,ជសេរ សយក Datasheet >

6. ក�ុង,បអប់ Data Mode េ,ជសេរ សយក Edit >

7. ចុច Save Button េហយក�ុង,បអប់ Macro Name សមូកំនត់ MacroOpenTableStudentList >

8. ចុច OK Button >

Page 26: Advance Access 2010 Khmer

22 www.enteritc.com Microsoft Access 2010 Advance

Enter Information Technology Center មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័

9. ចុច Run Button េដម�ីេមលលទ|ផល

3. �របេង(�ត Close Button:

1មឧ3ហរណ៍7ងេ,�មគឺ�បេង�ត Macro មួយេ<= ះ CloseTableStudentList េ!យឲQេធ@�របិទនូវ

TableStudentList ។

1. ចុច Create Tab >

2. ចុច Macro >

3. ក�ុង,បអប់ Add New Action េ,ជសេរ សយក CloseWindows >

4. ក�ុង,បអប់ Ojbect Type សមូេ,ជសេរ សយក Form >

5. ក�ុង,បអប់ Object Name សមូេ,ជសេរ សយក FormStudentList >

6. ក�ុង,បអប់ Save សមូេ,ជសេរ សយក Prompt >

7. ចុច Save Button េហយក�ុង,បអប់ Macro Name សមូកំនត់ MacroCloseFormStudentList >

8. ចុច OK Button >

Page 27: Advance Access 2010 Khmer

Access 2010 Advance www.enteritc.com 23

មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័ Enter Information Technology Center

4. រេប�ប)* ប ់Macro +មយួន-ង Form:

1មឧ3ហរណ៍7ងេ,�មគឺ��រ3ញយក Macro ចំនួនែដល�នេ<= ះដូច� MacroOpenTableStudentList និង

MacroCloseFormStudentList េ?�� ប់�មួយនឹង FormStudentList េដម�ីបេង�ត� Button ស&ំប់ឲ Form េ,ប,-ស។់ 1.

សមូេបក FormStudentList េហយចុច View >

2. Design View >

3. Uប់3ញ MacroCloseFormStudent និង MacroOpenTableStudentList េ?�ន់ទី1ំងែដល,ត]វ�រ >

Page 28: Advance Access 2010 Khmer

24 www.enteritc.com Microsoft Access 2010 Advance

Enter Information Technology Center មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័

4. ចុច View >

5. Design View

5. រេប�ប�សងទ់�ន.នយ័/ម Macro:

1មឧ3ហរណ៍7ងេ,�មគឺ��រប�9 ញពី�របេង�ត Macro េដម�ីេធ@�រ,សង់ទិន�ន័យពី FormStudentList េ?1ម

StudentID ែដល-នកំនត់េក�ុង Form ែដលនឹងបេង�តេ<= ះ FormDialog ។

1. ចុច Create Tab >

2. Macro >

3. យក TextBox មួយមកគូរេេល Form >

4. ,តង់ Property Sheet ក�ុង,បអប់ Name !ក់េ<= ះ FromStudentID >

5. យក TextBox មួយមកគូរេេល Form >

6. ,តង់ Property Sheet ក�ុង,បអប់ Name !ក់េ<= ះ ToStudentID >

7. ចុច Save Button េហយ!ក់េ<= ះ FormDialog >

8. ចុច OK Button >

Page 29: Advance Access 2010 Khmer

Access 2010 Advance www.enteritc.com 25

មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័ Enter Information Technology Center

9. ចុច Create Tab >

10. ចុច Macro Button >

11. ក�ុង,បអប់សមូQយ OpenForm >

12. ក�ុង,បអប់ Form Name េរ សយក FormStudentList >

13. ក�ុង,បអប់ View េរ សយក Form >

14. េ,តង់ែផ�ក7ង�G ំៃន,បអប់ Where Condition ចុច Build Button >

15. សមូសរេសរ �ក�7ងេ,�មចូលេ?ក�ុង,បអប់ >

StudentID >= Forms![FormDialog]![FromStudentID] and StudentID<= Forms![FormDialog]![ToStudentID]

Page 30: Advance Access 2010 Khmer

26 www.enteritc.com Microsoft Access 2010 Advance

Enter Information Technology Center មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័

16. សមូ Save េ!យ!ក់េ<= ះR MacroOpenFormStudentList >

17. ចុច OK Button >

18. ចុច Create Tab >

19. ចុច Macro Button >

20. សមូQយ�ក� CloseWindow ចូលេ?ក�ុង,បអប់ >

21. ក�ុង,បអប់ Ojbect Type េ,ជសេរ សយក Form >

22. ក�ុង,បអប់ Object Name េរ សយក FormDialog >

23. ក�ុង,បអប់ Save េរ សយក Prompt >

24. សមូ Save េ!យ!ក់េ<= ះR MacroCloseFormDialog >

25. ចុច OK Button >

26. សមូ,តលប់េ?�ន់ FormDialog វញិេហយយក Button មកគូរេក�ុង Form >

27. ចុច Cancel េេពលQប�9 ញ./ ំង Wizard >

Page 31: Advance Access 2010 Khmer

Access 2010 Advance www.enteritc.com 27

មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័ Enter Information Technology Center

28. ,តង់ Property Sheet េក�ុង,បអប់ Name សមូ!ក់េ<= ះR OpenFormStudentList >

29. ក�ុង,បអប់ Caption សមូសរេសរ Open >

30. ក�ុង,បអប់ ControlTip Text សមូសរេសរ Open FormStudentList >

31. ចុច Event Tab េហយេក�ុង,បអប់ On Click សមូេរ សយក MacroOpenFormStudent >

32. សមូ,តលប់េ?�ន់ FormDialog វញិេហយយក Button មកគូរេក�ុង Form >

33. ចុច Cancel េេពលQប�9 ញ./ ំង Wizard >

Page 32: Advance Access 2010 Khmer

28 www.enteritc.com Microsoft Access 2010 Advance

Enter Information Technology Center មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័

34. ,តង់ Property Sheet េក�ុង,បអប់ Name សមូ!ក់េ<= ះR Close >

35. ក�ុង,បអប់ Caption សមូសរេសរ Close >

36. ក�ុង,បអប់ ControlTip Text សមូសរេសរ Click to Close >

37. ចុច Event Tab េហយេក�ុង,បអប់ On Click សមូេរ សយក MacroCloseFormDialog >

38. Select េល Form >

39. ក�ុង,បអប់ Scroll bar េរ សយក Neither >

40. ក�ុង,បអប់ Record Selector េរ សយក No >

39. ក�ុង,បអប់ Navigation buttons េរ សយក No >

39. ក�ុង,បអប់ Dividing Line េរ សយក No >

39. ក�ុង,បអប់ Border Style េរ សយក Dialog >

39. ក�ុង,បអប់ Close button េរ សយក No

Page 33: Advance Access 2010 Khmer

Access 2010 Advance www.enteritc.com 29

មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័ Enter Information Technology Center

6. រេប�ប)* ប ់Macro +មយួន-ង ComboBox:

1មឧ3ហរណ៍7ងេ,�មប�9 ញពី�រ�� ប់ Macro �មួយនឹង ComboBox េដម�ីេធ@�រ,សង់យកទិន�ន័យមកប�9 ញ

េល Form េ?1ម ID ែដល-នេ,ជសេរ សយកេក�ុង ComboBox េ�ះ។

1. បេង�ត Query មួយេ<= ះ QueryCustomerIDAndName េ!យចុច Create Tab >

2. Query Wizard >

3. េរ សយក Simple Query Wizard >

4. ចុច OK Button >

5. ក�ុង,បអប់ Table/Queries េរ សយក TableCustomer >

6. ប(�ូ ន Filed CustmerID និង Name ចូលេ?ក�ុង,បអប់ Selected Fields >

7. ចុច Next Button >

8. ក�ុង,បអប់សមូ!ក់េ<= ះR QueryCustomerIDAndName >

9. ចុច Finish Button េហយបិទQេUល >

Page 34: Advance Access 2010 Khmer

30 www.enteritc.com Microsoft Access 2010 Advance

Enter Information Technology Center មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័

10. ចុច Create Tab >

11. Form Wizard >

12. ក�ុង,បអប់ Table/Queries េរ សយក TableCustomer >

13. ប(�ូ ន Filed 3ំងអស ់ចូលេ?ក�ុង,បអប់ Selected Fields >

14. ចុច Next Button >

15. េ,ជសេរ សយក Columnar >

16. ចុច Next Button >

Page 35: Advance Access 2010 Khmer

Access 2010 Advance www.enteritc.com 31

មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័ Enter Information Technology Center

17. ក�ុង,បអប់សមូ!ក់េ<= ះR FormCustomer >

18. ចុច Finish Button េហយបិទQេUល >

19. ចុច Create Tab >

20. ចុច Macro Button >

21. ក�ុង,បអប់ Add New Action េរ សយក GoToControl >

22. ក�ុង,បអប់ Control Name សមូ!ក់េ<= ះ CustomerID >

23. ក�ុង,បអប់ Add New Action េរ សយក FindRecord >

24. ក�ុង,បអប់ Find What សមូសរេសរ =[Cust-ID] >

Page 36: Advance Access 2010 Khmer

32 www.enteritc.com Microsoft Access 2010 Advance

Enter Information Technology Center មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័

25. ក�ុង,បអប់ Add New Action េរ សយក SetTempVar >

26. ក�ុង,បអប់ Name សមូសរេសរ =[Cust-ID] >

27. ក�ុង,បអប់ Expression សមូសរេសរ =CustomerID >

28. ចុច Save Button េហយ!ក់េ<= ះR MacroFindRecord >

29. ចុច OK Button >

30. សមូេបក FormCustomer � Design View >

31. យក ComboBox មកគូរេក�ុង Form >

Page 37: Advance Access 2010 Khmer

Access 2010 Advance www.enteritc.com 33

មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័ Enter Information Technology Center

32. ចុច Cancel Button >

33. ក�ុង Label របស ់ComboBox សរេសរ Find ID >

34. ,តង់ Properties ក�ុង,បអប់ Name សមូ!ក់េ<= ះ Cust-ID >

35. ចុច Data Tab >

36. ,តង់ Row Source េរ សយក QueryCustomerIDAndName >

Page 38: Advance Access 2010 Khmer

34 www.enteritc.com Microsoft Access 2010 Advance

Enter Information Technology Center មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័

37. ចុច Event Tab >

38. ,តង់ After Update េរ សយក MacroFindRecord >

39. ចុច Save Button >

40. ចុច View >

41. Design View >

Page 39: Advance Access 2010 Khmer

Access 2010 Advance www.enteritc.com 35

មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័ Enter Information Technology Center

42. ប�/ ប់មកេយងនឹងទទួល-នលទ|ផលដូច7ងេ,�ម

Page 40: Advance Access 2010 Khmer

36 www.enteritc.com Microsoft Access 2010 Advance

Enter Information Technology Center មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័

Page 41: Advance Access 2010 Khmer

Access 2010 Advance www.enteritc.com 37

មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័ Enter Information Technology Center

េមេរ�នទ� 3: �រស�ក�ព� VBA (Visual Basic for Application)

1. ន�យមនយ័:

VBA គឺ���កមវធិីមួយ េ�ក�ុងចំេ�ម��កមវធិី�េ�ចន ែដល�ត�វ!នេ�ប�!សេ់�េល�បេភទ Application

មួយចំនួនដូច� Word, Excel, និង�ពិេសស�មួយ Microsoft Access េដម)ីឲអ�កេ�ប�!ស-់ចបេង.ត Application

/មួយថីេ12មតំរវូ4រ។ ឧ7ហរណ៍ដូច�េ�ក�ុង Access គឺ-ចយក VBA មកសរេសរបេង.ត� Function ថី

ែដលមិន7ន់;ន ឬសរេសរបេង.ត Event េ1ឲ Object �េដម។

2. Module: Code របស ់VBA ែដលេយង!នសរេសរ គឺ�ត�វ!នរក=ទុកេ�ក�ុង Module ដូេច�ះ Module គឺ�កែន?ងែដលេយង

សរេសរបេង.ត Procedure េ@យេ�ប�!ស ់Code របស ់VBA ។

េ�ក�ុង Module ;ន Module ពីរ�បេភទដូចD� :

> Private (Form, Report, Module) ែដលេយង-ចសរេសរេ@យKL លេ់1 Form ឬ Report KL លែ់តមNង

> Public (Global Module) ែដលេយង-ចបេង.ត Public Module េ�@ច់េ@យែឡកពី Objects េ�ក�ុង Database

េ@យេយងេ�បUសXំប់ផLុក Code ែដល-ចយកេ1េ�ប�!ស!់ន�គប់កែន?ងៃន Objects ក�ុង Database ។

3. Procedure: Procedure គឺ�បណNុ ំ ៃន Statement ែដលសរេសរបេង.តេឡយេ@យ Code របស ់VBA សXំប់ ដំេន4រ4រ\រ/

មួយេ12មតំរូវ4រ េ@យក�ុងេ�ះ Procedures �ត�វ!នែបងែចក�ពីរ�បេភទេទ]តដូច� Function Procedures និង

Sub Procedures ។

> Fuction Procedure គឺ� Procedure ែដលេធ^4រ គណ�/មួយែដលេ!ះតំៃលលទ_ផល (Return Value)

េ14ន់តំបន់ែដល េ`Uេ�ប។

> Sub Procedure: គឺ� Procedure ែដលេធ^4រប\g ញពីព័ត៌;នេផwងៗ ឬក-៏ច�4រគណ� ប៉ុែនNេ!ះតំៃល

លទ_ផល (Return Value) េ14ន់តំបន់ែដល េ`Uេ�ប េ�ះេទ។ �គេ�ចន Sub Procedure គឺ�ត�វេ�ប�!ស�់| ប់

�មួយនឹង Form ឬ Report KL លែ់តមNង។

4. �របេង��ត Event Procedure:

2មឧ7ហរណ៍~ងេ�4មនឹងប\g ញពី4រសរេសរ VBA Code �| ប់�មួយនឹង Button េដម)ីបិទ FormBiography ។

1. េបក FormBiography �ទំរង់ DesignView >

2. យក Button មួយមកគូរេ�េល Form >

Page 42: Advance Access 2010 Khmer

38 www.enteritc.com Microsoft Access 2010 Advance

Enter Information Technology Center មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័

3. ចុច Cancel Button >

4. �តង់ Properties ចុច All Tab >

5. ក�ុង�បអប់ Name @ក់េ� ះ� CmdClose >

6. ក�ុង�បអប់ Caption សមូសរេសរ Close >

7. �តង់ Properties ចុច Event Tab >

8. ក�ុង�បអប់ On Click សមូចុច Build Button >

Page 43: Advance Access 2010 Khmer

Access 2010 Advance www.enteritc.com 39

មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័ Enter Information Technology Center

9. េ�ជសេរ សយក Code Builder >

10. ចុច OK OK Button >

11. េ��តង់ចេ�? ះ Private Sub និង End Sub សមូសរេសរ >

DoCmd.Close

12. បិទKL ំង VBA េចញវញិ េហយចុច view >

13. Form View េដម)ីេមលលទ_ផល >

Page 44: Advance Access 2010 Khmer

40 www.enteritc.com Microsoft Access 2010 Advance

Enter Information Technology Center មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័

14. ~ងេ�4មេនះ�លទ_ផលែដលទទួល!ន

5. ស�ក�ព� Pre-Build Function:

Pre-Build Function គឺ� Function ែដល;ន��ប់េ�ក�ុងកមវធិី Microsoft Access KL លែ់តមNង។

~ងេ�4មេនះ� Function មួយចំនួនែដល;ន��ប់េ�ក�ុងកមវធិី:

> IsNull(varxpr) : Uទទួលយកតំៃលពិតេ�េពលែដលមិន;នទិន�ន័យ

> Month(date) : �ប់យកែខ

> Year(date) : �ប់យក�� ំ

> Day(date) : �ប់យកៃថ�ទីពី 1 រហតូដល ់31

> Weekday(date): �ប់យក index ៃនៃថ�ក�ុងមួយស!N ហ ៍េ@យប\g ញពីេលខ 1 ដល ់7

> Minute(date) : �ប់យក�ទី

> Hour(date) : �ប់យកេ;៉ង

> Second(date) : �ប់យកវ�ិទី

> IsNumeric(varexpr) : Uទទួលយកតំៃលពិតេ�េពលែដលទិន�ន័យ�េលខ

> Format(expr,formattype): កំនត់�ទង់�7យៃនទិន�ន័យ

Page 45: Advance Access 2010 Khmer

Access 2010 Advance www.enteritc.com 41

មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័ Enter Information Technology Center

> Len(string) : Xប់ចំនួនតួអកwរែដល;នេ�ក�ុង String

> Left(String,n) : 4ត់យកតួអកwរេ@យគិតពីេឆ̂ងេ1

> Mid(string,start,n) : 4ត់យកតួអកwរេ12មទី2ំងែដល�ត�វ4រ

> Right(string,n) : 4ត់យកតួអកwរេ@យគិតពី�N ំ េ1េឆ̂ង

> Ucase(string) : សXំប់បំែលងទិន�័យឲេ1�អកwរធំ7ំងអស់

> Lcase(string) : សXំប់បំែលងទិន�ន័យេ1�អកwរតូច7ំងអស់

> Trim(string) : សXំប់លបុ Space ែដលេ�~ងមុខនិង~ងេ�4យទិន�័យេ�ល

6. �របេង��ត Function ក!ុង Public Procedure:

2មឧ7ហរណ៍~ងេ�4មេនះនឹងប\g ញពី4របេង.ត Function មួយេ� ះ Capfirst ែដលU;នតួ�ទីក�ុង4រ

Convert ឲតួអកwរដំបូងេ1�អកwរធំ ។

1. ចុច Create Tab >

2. Module >

3. សមូសរេសរ VBA Code ដូច~ងេ�4ម >

4. ចុច Save Button េហយ@ក់េ� ះ� ModuleUtilities >

5. ចុច OK Button េហយបិទKL ំងUេ�ល >

6. េបក FormCustomer � Design View េហយ Select េល TextBox Name >

7. �តង់ Property Sheet ក�ុង�បអប់ Control Source សមូចុច Build Button >

Page 46: Advance Access 2010 Khmer

42 www.enteritc.com Microsoft Access 2010 Advance

Enter Information Technology Center មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័

8. ក�ុង�បអប់ Expression Builder សមូសរេសរ >

= Capfirst( Form![Name] )

9. ក�ុង�បអប់ Name សមូបNូ រេ� ះេ1� Names េហយចុច Save Button >

Page 47: Advance Access 2010 Khmer

Access 2010 Advance www.enteritc.com 43

មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័ Enter Information Technology Center

10. សមូ Switch េ14ន់ Form View េហយេយងនឹងទទួល!នលទ_ផលដូច~ងេ�4ម

7. �រេ#$�#%ស ់Comment:

េ�ក�ុង4រសរេសរ Program គឺែតងែតេធ^កំនត់ សDំលេ់ផwងៗ េ�ក�ុង Code ឬ Statement េដម)ីប¤| ក់ពីអត¥ន័យ

បែន¥ម និង\យ�ស¦លេមល េ@យUមិន�ត�វ!នដំេន4រេ�ះេទ ។ ចំេ§ះ Comment គឺ�ត�វ!នសរេសរេ@យ@ក់

ស¤̈ ( ' ) Apostrophe េ�~ងមុខ Statement ែដល� Comment ។

Ex:

8. �រេ#$�#%ស ់Statement:

េ�ក�ុង4រសរេសរ VBA របស ់Access Statement គឺ�ជួរអកwរែដលសរេសរមួយប�L ត់ៗ េហយបª« ប់�មួយនឹង

4រចុះប�L ត់ (Enter Key) ។ ក�ុងេ�ះ�បសនិេប មួយ Statement ែដល!នសរេសរ;នចុះប�L ត់េ�ះនឹង;ន Error

េកតេឡង។

Ex:

Page 48: Advance Access 2010 Khmer

44 www.enteritc.com Microsoft Access 2010 Advance

Enter Information Technology Center មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័

ក�ុងករណីែដលេយង�ត�វ4រចុះប�L ត់ េ�ក�ុង Statement េ@យមិនឲ;ន Error េកតេឡងេ�ះេយង�ត�វបែន¥ម

�មួយនឹង Underscore េ�~ងចុងៃន ¬? ែដល�ត�វ4រចុះប�L ត់ ។

Ex:

េហយេដម)ីេធ^4រសរេសរ Statement �េ�ចនេ�េលជួរែតមួយវញិេ�ះគឺ�ត�វេ�ប�!សស់¤̈ Colon (: ) ។

Ex:

Page 49: Advance Access 2010 Khmer

Access 2010 Advance www.enteritc.com 45

មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័ Enter Information Technology Center

9. ក'នួក!ុង�រកំនតេ់*+ ះឲ Elements:

�មួយនឹងក)ួនក�ុង4រ@ក់េ� ះឲ Elements នីមួយៗដូច� Sub Procedures, Function Procedures, Variable,…

គឺ�ត�វេDរព2មេDល4រណ៍ែដល!នកំនត់ដូច�:

1. �ត�វ�ប់េផNមតួដំបូងេ@យអកwរ (Letter)

2. តួប�L ប់-ច�អកwរ, េលខ និង Underscore

3. ®មដក¬? និងេ�ប�!សន់ិមិតស¤̈ពិេសស

4. ®មេ�ប�!ស ់(Reserved Keyword)

5. ®មសរេសរេលពី 40 តួអកwរ ។

Reserved Keyword គឺ�§ក¯បំរងុទុកែដល VBA Code ទុកេ�ប�!សK់L លខ់?ួន េដម)ីប¤| េ1េលដំេន4រ 4រ\រ

/មួយែតប៉ុេ/° ះ។ Reserved Keyword មួយចំនួន;នដូច� If, Loop, Len, Mid, Close, Or, Mod,… ។

10. ស�ក�ព� Variable:

Variable គឺ�កែន?ងសXំប់រក=ទិន�ន័យឬតំៃលេ�ក�ុង Memory េហយU�អ�កកំនត់ពីទំហៃំនតំៃលសXំប់េ�ប�!ស ់

េ�ក�ុង Memory ផងែដរ។ ក�ុង4រេ�ប�!ស ់Variable គឺេយង�ត�វេធ̂4រ�ប4សU�មុនសនិ ប�L ប់េទប-ចផNលត់ំ

ៃលេ1ឲU ឬេ�ប�!សU់េ�េពលេ�4យ។

> Dim គឺ� Keyword សXំប់េ�ប�!សេ់ដម)ីេរ]បចំក�ុង4របេង.ត Variable

> VariablName គឺ�េ� ះរបស ់Variable ែដល�ត�វបេង.តេ@យេDរព2មក)ួនៃន4រកំនត់េ� ះរបស ់Element

> As គឺ� Keyword សXំប់េរ]បចំក�ុង4របេង.ត Data Type

> Type គឺ� �បេភទទិន�ន័យ (Data Type) ែដលកំនត់ឲ Variable �ត�វទទួលយកេ1េ�ប�!ស ់។

ក�ុងករណីែដលេយងលបុ Data Type េ�លេ�ះUនឹងយក Data Type �បេភទ Variant េ1ឲ Variable វញិ។

Syntax: Dim VariableName [As Type]

Ex: Dim Result As Integer Dim Discount As Double Dim Birthdate As Variant Dim Name As String Dim Temp Dim Temp As Variant

Page 50: Advance Access 2010 Khmer

46 www.enteritc.com Microsoft Access 2010 Advance

Enter Information Technology Center មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័

11. Implicit Vs. Explicit Declaration: េដម)ីេ�ប�!ស ់Variable !នលះុ�2/េយង�ប4ស (Declare) U�មុនសនិ េហយក�ុង4រ Declare Variable គឺ

�ត�វ!នែបងែចក� 2 �បេភទដូច�: Implicit និង Explicit ។

> Implicit Declaration គឺ�េ�ប�!ស ់Variable េ@យពំុ�ំ!ច់ Declare Uេ�ះេទ េ@យUនឹងយក Data Type �ប េភទ

Variant ឲ Varaible េ@យស^�័បវតNិេហយ-ចេ�ប�!សេ់@យមិន;ន Error េកតេឡងេ�ះេទ។ ក�ុងេ�ះេយង

�ត�វលបុ¬? Option Explicit េចញពីតំបន់ Delcarations Section ។ ប៉ុែនN4រេ�ប�!ស ់Variable េ@យមិន Declare U

-ចបង.ឲ\យ Error េហយពិ!កក�ុង4រ �ត¦តពិនិត¯~? ំង/ស ់ដូេច�ះវធិី�±សNដល៏²ក�ុង4រេ�ប�!ស ់Variable គួរ

ែត Declare Uមុននឹងេ�ប�!ស ់។

Ex: 2មឧ7ហរណ៍~ងេ�4ម Varible x និង Variable Temp ��បេភទ Implici Declaration ;នន័យេយង-ច

យកUមកេ�ប�!សេ់@យពំុ�ំ!ច់ Declare េ�ះេទ។

> Explicit Declaration គឺ�េ�ប�!ស ់Variable េ@យ�ំ!ច់�ត�វែត Declare Uមុនេទបេ�ប�!ស2់មេ�4យ ។

ក�ុងេ�ះ @ច់~តេយង�ត�វសរេសរបែន¥មនូវ¬? Option Explicit េ�ក�ុងតំបន់ Delcarations Section ។

Ex: 2មឧ7ហរណ៍~ងេ�4ម Option Explicit �ត�វ!នបែន¥មេ��តង់តំបន់ Delcarations Section ដូេច�ះ Variable

Temp @ច់~ត�ត�វ Declare មុននឹងេ�ប�!សU់

Page 51: Advance Access 2010 Khmer

Access 2010 Advance www.enteritc.com 47

មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័ Enter Information Technology Center

12. ស�ក�ព� Data Type:

Data Type គឺ��បេភទទិន�ន័យែដល Varible �ត�វទទួលយក ដូេច�ះេ�េពលែដលេយង Declare Variable គឺេយង

�ត�វកំនត់ពី Data Type េ1ឲU!នផងែដរ។ �បសនិេបេយងមិនកំនត់ Data Type េ1ឲ Varaible េ�ះេទ េ�ះUនឹង

យក Data Type � Variant េ@យស^យ័�បវតNិ។

~ងេ�4មេនះ� Table ប¤| ក់ពី Data Type របស ់Microsoft Access:

Data Type Size Range Byte 1 byte 0 to 255

Boolean 2 byte True or False

Integer 2 byte -32,768 to 32,767

Long

(long integer)

4 byte -2,147,483,648 to 2,147,483,647

Single

( double-precision

floating-point)

4 byte -3.2823E38 to -1.401298E-308 to

-494065645841247E-324 for negative values,

4.94065645841247E-324 to 1.79769313486232E308

For positive values,

Currency

( scaled integer)

8 byte -922, 337, 203, 685, 477, 5808 to

922, 337, 203, 685, 477, 5807.

Decimal 14 byte +/-79, 228, 162, 514, 264, 337, 593, 543, 950, 335

With no decimal point.

+/-7.9228162514264337593543950335 with 28

places to the right of the decimal, smallest non-zero number is.

+/-0.000000000000000001

Date 8 byte January 1, 100 to December 31,9999

Object 4 byte Any Object reference

String

(variable-length)

10 bytes +

String length

0 to approximately 2 billion

String

(fixed-length)

Length of string 10 to approximately 65,400

Variant

(with numbers)

16 byte

Any numeric value up to the range of a Double

Variant

(with characters)

22 byte +

String length

Same range as for variable-length SString

User--defined

(using Type)

Number

Required by

elements

Th range of each element is the same as the rang of its data

type.

Page 52: Advance Access 2010 Khmer

48 www.enteritc.com Microsoft Access 2010 Advance

Enter Information Technology Center មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័

13. Variable & Data Type Pratical: 2មឧ7ហរណ៍~ងេ�4មប\g ញពី4របេង.ត4រគណ� េ@យេ�ប�!ស ់Variable �មួយនឹង Data Type ។

1. យក TextBox មកគូរេល Form េហយក�ុង Label @ក់េ� ះ Value 1: >

2. �តង់ Property Sheet ចុច All Tab េហយក�ុង�បអប់ Name @ក់េ� ះ TextValue1 >

3. យក TextBox មកគូរេល Form េហយក�ុង Label @ក់េ� ះ Value 2: >

4. �តង់ Property Sheet ចុច All Tab េហយក�ុង�បអប់ Name @ក់េ� ះ TextValue2 >

5. យក TextBox មកគូរេល Form េហយក�ុង Label @ក់េ� ះ Result: >

6. �តង់ Property Sheet ចុច All Tab េហយក�ុង�បអប់ Name @ក់េ� ះ TextResult: >

7. យក Button មកគូរេល Form េហយចុច Cancel េ�េពលKL ំង Wizard ប\g ញេឡង >

Page 53: Advance Access 2010 Khmer

Access 2010 Advance www.enteritc.com 49

មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័ Enter Information Technology Center

8. �តង់ Property Sheet ចុច All Tab េហយក�ុង�បអប់ Name @ក់េ� ះ ButtonSum: >

9. ក�ុង�បអប់ Caption សរេសរ Sum >

10. ចុច Event Tab េហយចុច Build Button >

11. េ�ជសេរ សយក Code Builder >

12. ចុច OK Button >

Page 54: Advance Access 2010 Khmer

50 www.enteritc.com Microsoft Access 2010 Advance

Enter Information Technology Center មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័

13. សមូ សរេសរ VBA Code ដូច~ងេ�4ម ប�L ប់មកសមូ Save េហយបិទUេ�ល >

14. �តឡប់មក4ន់ Form Design វញិេហយសមូ Save ទុកេ@យ@ក់េ� ះ� FormVariablePratical >

15. ចុច OK Button >

16. យក Button មកគូរេ�ក�ុង ButtonSum េហយចុច Cancel េ�េពលប\g ញKL ំង Wizard >

17. ក�ុង Properties �តង់�បអប់ Name @ក់េ� ះ� ButtonClear >

18. �តង់�បអប់ Caption សរេសរ Clear >

Page 55: Advance Access 2010 Khmer

Access 2010 Advance www.enteritc.com 51

មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័ Enter Information Technology Center

19. ចុច Event Tab >

20. ចុច Build Button >

21. េរ សយក Code Builder >

22. ចុច OK Button >

23. សមូសរេសរ VBA Code ដូច~ងេ�4ម >

24. ចុច View >

25. Form View >

Page 56: Advance Access 2010 Khmer

52 www.enteritc.com Microsoft Access 2010 Advance

Enter Information Technology Center មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័

26. ~ងេ�4មេនះ�លទ_ផលែដលទទួល!ន

14. Scope Variable:

Scope Variable គឺ�4រប\g ញពីវ�ិល�ព ៃនទី2ំងែដល Variable -ច�ត�វេ�ប�!ស!់ន ែដលក�ុងេ�ះ Variable

�ត�វ!នែបងែចក� 3 Scope រមួ;ន:

> Local Variable: គឺ� Variable េ�ប�!ស�់មួយនឹង Dim ែដលU-ចេ�ប�!ស!់នេ�ក�ុងែត Procedure ែដល

Declare Uែតបុ៉េ/° ះ។

Page 57: Advance Access 2010 Khmer

Access 2010 Advance www.enteritc.com 53

មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័ Enter Information Technology Center

Ex: Variable msg គឺ-ចេ�ប�!សេ់�ក�ុង ButtonSum !ន ប៉ុែនNមិន-ចេ�ប�!ស ់េ�ក�ុង ButtonClear !នេទ។

> Module (Private) Vairable: គឺ� Variable េ�ប�!ស�់មួយនឹង Dim ឬ Private ែដល declare េ�ក�ុង Declaration

Section េ@យU-ចេ�ប�!ស!់ន េ��គប់ Procedures ក�ុង Module ែតមួយ!ន ប៉ុែនNមិន-ចេ�ប �!សេ់�ក�ុង

Module េផwងៗេទ]ត!នេទ។

Ex: Variable msg គឺ�ត�វ!ន Declare េ�ក�ុង Declaration េ@យេយង-ចយកUេ1េ�ប�!សេ់�ក�ុង ButtonSum

!ន េហយក-៏ចេ�ប�!ស ់េ�ក�ុង ButtonClear !ន។

Page 58: Advance Access 2010 Khmer

54 www.enteritc.com Microsoft Access 2010 Advance

Enter Information Technology Center មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័

> Global (Public): គឺ� Variable េ�ប�!ស�់មួយនឹង Public ែដល declare េ�ក�ុង General Declaration Section

(េ�ក�ុង Module ) េ@យU-ចេ�ប�!ស!់ន េ��គប់ Procedures ក�ុង Module �េ�ចន!នផងែដរ ។

Ex: Variable msg គឺ�ត�វ!ន declare េ�ក�ុង ModuleGlobal ែដលU-ចេ�ប�!សេ់��គប់កែន?ង7ំងអស។់

Page 59: Advance Access 2010 Khmer

Access 2010 Advance www.enteritc.com 55

មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័ Enter Information Technology Center

15. Local Variable Vs. Static Variable: > Local Vairable គឺ� Variable ែដលរក=តំៃលទុកបេ/N ះ-សន�រហតូដល ់Procedure �ត�វ!នបª« ប់ េ�ះUនឹង

Clear តំៃលែដល;នេ�ល េហយនឹងទទួលយកតំៃលថីេ�េពលែដល Procedure �ត�វ!នដំេន4រេឡងវញិ។

Ex: ចំេ§ះ Label គឺ!នប\g ញ� You click 1 Time(s) �េរ]ងរហតូេ�េពលែដលេយងចុចេល Button Click បុ៉� ន

ដងកេ៏@យ ពីេ�§ះ េ�ក�ុង Code េយង!នកំណត់ Variable i � Local Variable ។

Page 60: Advance Access 2010 Khmer

56 www.enteritc.com Microsoft Access 2010 Advance

Enter Information Technology Center មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័

> Static Variable គឺ� Variable ែដលរក=តំៃលទុកបេ/N ះ-សន�ែដរ ប៉ុែនNរហតូដល ់កមវធិី �ត�វ!នបª« ប់ េ�ះU

នឹង Clear តំៃលែដល;នេ�ល េហយនឹងទទួលយកតំៃលថីេ�េពលែដល កមវធិី �ត�វ!នដំេន4រេឡងវញិ។

Ex: េ�ក�ុង Lable -ចXប់ចំនួនដងែដលេយង!នចុចេល ButtonClick -�សយ័េល Variable i ែដល� Static

Variable ។

Page 61: Advance Access 2010 Khmer

Access 2010 Advance www.enteritc.com 57

មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័ Enter Information Technology Center

េមេរ�នទ� 4: ស�ក�លំអ�តព� VBA (Visual Basic for Application)

1. Control Execution:

ក�ុង VBA គឺ�តវែតងែត�តវ នេ�ប� ស�់មួយនឹង Condition Structures និង Loop Structure �និច�។

> Condition Structures គឺ��រសរេសរ Code េដម!ីកំនត់ពីលក&ខណ) ៃន�រដំេន�រតំបន់ៃន Code +មួយ

ឧ-ហរណ៍: េយង0ចេ�ប� ស ់Condition Structure េដម!ីកំនត់1�បសនិេបពិន2ុ របសស់សិ34ប់ពី 50 េឡងេ8

ឲេធ<�រក�ុង Block ៃន Code ដំបូងគឺប?@ ញ Message 1 Pass ប៉ុែនF�បសនិេបពិន2ុ របសស់សិ3តិច�ង 50 េGះឲI

Skip េ4លនូវ Block ៃន Code ដំបូងេហយេ8ដំេន�រៃន Block ៃន Code បG2 ប់ដូច� ប?@ ញ Message 1 Fail

�េដម។ Kគេ�ចន Condition Structure �តវ នKN ប់�មួយនឹង Query, Form, Report, SQL Statement,

�ពិេសសសTំប់ យកមកេ�ប� ស�់មួយនឹង VBA U2 លែ់តមFង។

Codtion Structures Wនដូច�:

> If Then

> If Then Else

> Select Case ។

> Loop Structure គឺ��រសរេសរ Code េដម!ីកំនត់ពីចំនួនដងៃន�រដំេន�រតំបន់ៃន Code +មួយ

ឧ-ហរណ៍: េយង0ចេ�ប� ស ់Loop Structure េដម!ីកំនត់ឲ ពិន2ុ �តវ នប[�ូ លមFងេហយមFងរហតូដល ់5 ដង

េ8ក�ុង Code �េដម។

Loop Structures ែដល�តវេ�ប� សW់នដូច�:

> Do Loop While

> Do While Loop

> For Loop ។

2. If Then Condition Structure: If Then �តវ នេ�ប� សេ់ដម!ីដំេន�រៃន Block of Statements េ8^មលក&ខណ) True េ_យ0ចសរេសរែត 1

Statement សTំប់_ក់លក&ខណ) ឬក�៏សរេសរេ�ចន Statement េដម!ី_ក់លក&ខណ) នផងែដរ។

Syntax 1 Statment:

If <Condition> Then <Statement>

Page 62: Advance Access 2010 Khmer

58 www.enteritc.com Microsoft Access 2010 Advance

Enter Information Technology Center មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័

Example:

Syntax Multiple Statment:

If <Condition> Then

<Statement>

End If

Page 63: Advance Access 2010 Khmer

Access 2010 Advance www.enteritc.com 59

មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័ Enter Information Technology Center

Example:

3. If Then Else Condition Structure: If Then Else �តវ នេ�ប� សេ់ដម!ីដំេន�រៃន Block of Statements េ8^មលក&ខណ) True ែដលក�ុងេGះ

លក&ខណ) �តវ នកំនត់4ប់ពី ពីរេឡងេ8។

Syntax:

If <Condition-1> Then

<Statement-1>

ElseIf <Condition-2> Then

<Statement-2>

ElseIf <Condition-n> Then

<Statement-n>

Else

<Statement-Else>

End If

Page 64: Advance Access 2010 Khmer

60 www.enteritc.com Microsoft Access 2010 Advance

Enter Information Technology Center មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័

Example:

Page 65: Advance Access 2010 Khmer

Access 2010 Advance www.enteritc.com 61

មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័ Enter Information Technology Center

4. Select Case Condition Structure: Select Case �តវ នេ�ប� សេ់ដម!ីដំេន�រៃន Block of Statements េ8^មលក&ខណ) True ែដលក�ុងេGះ

លក&ខណ) �តវ នកំនត់4ប់ពី ពីរេឡងេ8ដូចv� នឹង If Then Else ែដរ ។

Syntax:

Example 1:

Select Case <TestExpression>

Case <Expression-1>

<Statement-1>

Case <Expression-2>

<Statement-2>

Case <Expression-n>

<Statement-n>

Case Else

<Statement-Else>

End Select

Page 66: Advance Access 2010 Khmer

62 www.enteritc.com Microsoft Access 2010 Advance

Enter Information Technology Center មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័

`

Example 2:

Page 67: Advance Access 2010 Khmer

Access 2010 Advance www.enteritc.com 63

មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័ Enter Information Technology Center

5. Do Loop While Structure: Do Loop While គឺ�តវ នេ�ប� សេ់ដម!ីដំេន�រ Block of Statement ដែដល�េ�ចនដង េxេពលែដលលក&ខណ)

ពិត ។ ក�ុងេGះ Do Loop While គឺIនឹងដំេន�រ Block of Statement មួយដងសនិេទប �ត{តពិនិត|េមលលក&ខណ)

^មេ��យ �បសនិេប លក&ខណ) ពិត េGះIនឹងបនFេធ<េឡងវញិ ប៉ុែនF�បសនិេបលក&ខណ) មិនពិតេទ Iនឹង4កេចញពី

Loop ។

Syntax:

Example:

Do <Statements> Loop while <Condition>

Page 68: Advance Access 2010 Khmer

64 www.enteritc.com Microsoft Access 2010 Advance

Enter Information Technology Center មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័

ក�ុងេGះ Do Loop Until 0ចេ�ប� សវ់ញិមFង េដម!ី�ត{តពិនិត|1 បG2 ប់ពីដំេន�រ Block of Statement ន

មFងេGះI�ត{តពិនិត|េមលលក&ខណ) �បសនិេប លក&ខណ) មិនពិតេទ េGះIនឹងបនFេធ<េឡងវញិ រហតូដល ់លក&ខណ)

ពិតIនឹង4កេចញពី Loop ។

Syntax:

Example:

6. Do While Loop Structure:

Do While Loop គឺ�តវ នេ�ប� សេ់ដម!ីដំេន�រ Block of Statement ដែដល�េ�ចនដង េxេពលែដលលក&ខណ)

ពិត ។ ក�ុងេGះ Do While Loop គឺI�ត{តពិនិត|េមលលក&ខណ) �មុនសនិ �បសនិេប លក&ខណ) ពិត េGះIនឹងដំេន

�រ Loop បុ៉ែនF�បសនិេបលក&ខណ) មិនពិតេទ Iនឹង4កេចញពី Loop ។

Do <Statements> Loop while Until <Condition>

Page 69: Advance Access 2010 Khmer

Access 2010 Advance www.enteritc.com 65

មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័ Enter Information Technology Center

Syntax:

Example:

ក�ុងេGះ Do Until 0ចេ�ប� សវ់ញិមFង េដម!ី�ត{តពិនិត|េមលលក&ខណ) �បសនិេប លក&ខណ) មិនពិតេទ េGះIនឹង

ដំេន�រ Loop រហតូដល ់លក&ខណ) ពិតេទបIនឹង4កេចញពី Loop ។

Syntax:

Do While <Condition> <Statements> Loop

While <Condition> <Statements> Wend

Do while Until <Condition> <Statements> Loop

Page 70: Advance Access 2010 Khmer

66 www.enteritc.com Microsoft Access 2010 Advance

Enter Information Technology Center មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័

Example:

7. For Loop Structure: For Loop គឺ�តវ នេ�ប� សេ់ដម!ីដំេន�រ Block of Statement េ8^មចំនួនដងែដល នកំនត់។

Syntax:

For <Counter> = <Start> To <end> <Step Increment> <Statements> Next <Counter>

Page 71: Advance Access 2010 Khmer

Access 2010 Advance www.enteritc.com 67

មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័ Enter Information Technology Center

Example:

Page 72: Advance Access 2010 Khmer

68 www.enteritc.com Microsoft Access 2010 Advance

Enter Information Technology Center មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័

8. �រេ�����ស ់Radio Button:

Page 73: Advance Access 2010 Khmer

Access 2010 Advance www.enteritc.com 69

មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័ Enter Information Technology Center

9. �រេ�����ស ់CheckBox:

Page 74: Advance Access 2010 Khmer

70 www.enteritc.com Microsoft Access 2010 Advance

Enter Information Technology Center មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័

11. លំ"ត:់

Page 75: Advance Access 2010 Khmer

Access 2010 Advance www.enteritc.com 71

មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័ Enter Information Technology Center

េមេរ�នទ� 5: �រែណ�ំព� DAO (Data Access Object)

1. Control Execution:

DAO គឺ�ត�វ�នេ�ប��សេ់ដម�ី access េ��ន់ Database ឬ Table, Query េ�យ�� ល ់េដម�ីេធ��រ�ញទិន#ន័យ

មកប&' ញេល Form , ែកែ�បទិន#ន័យ)សែ់ដល*ន ែស�ងរកទិន#ន័យ បែន-មទិន#ន័យថ/ី និងលបុទិន#ន័យ)សេ់ចញ

2េដម។

4មឧទហរណ៍9ងេ��មនឹងប&' ញពី�រេ�ប��ស ់DAO េដម�ីប<=ូ លទិន#ន័យពី FormProduct េ��ន់

TableProduct ។

1. បេងBត TableProduct 4មទំរង់ដូច9ងេ��ម >

2. បេងBត FormProduct 4មទំរង់ដូច9ងេ��ម >

3. សរេសរ VBA Code ដូច9ងេ��ម >

Page 76: Advance Access 2010 Khmer

72 www.enteritc.com Microsoft Access 2010 Advance

Enter Information Technology Center មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័

2. �រ���ស Database Object:

េដម�ី access េ��ន់ Database KមួយេMះេយង�ត�វ�ប�ស Variable *ន�បេភទ2 DAO.Database 2មុនសនិ

ែដលក#ុងេMះ�ត�វេSរព4ម Syntax ដូច9ងេ��ម:

Syntax: Ex:

បM� ប់មកពី�ន�ប�ស VariableDatabase េហយេMះេយង�ត�វេបកXេ�ប��សេ់�យេ�បទំរង់ Syntax 9ងេ��ម:

Syntax: > Currentdb *នន័យY េបកយក Database ែដលេយងកំពុងេធ��រេល

> DAO.Opendatabase("Path\File") *នន័យYេបកយក Database េផ_ងេទ`តេfក#ុងទី4ំងKមួយ

Dim <VariableDatabase> As DAO.Database

Dim db As DAO.Database

Set <VariableDatabase> = Currentdb Or Set <VariableDatabase> = DAO.Opendatabase("path\file")

Page 77: Advance Access 2010 Khmer

Access 2010 Advance www.enteritc.com 73

មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័ Enter Information Technology Center

Ex:

3. �រេ�����ស ់TableDef Object:

TableDef Object �ត�វ�នេ�ប��ស2់មួយនឹង DAO េដម�ីប&' ញkលព់័ត៌*នមួយចំនួនរបស ់Table េfក#ុង Database

Ex: ឧ�ហរណ៍9ងេ��មគឺ2�រប&' ញពីេw/ ះ Table �ំងអសែ់ដល*នេfក#ុង Database

Set db = Currentdb Set db = DAO.Opendatabase("C:\Enter.accdb")

Page 78: Advance Access 2010 Khmer

74 www.enteritc.com Microsoft Access 2010 Advance

Enter Information Technology Center មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័

Ex: ឧ�ហរណ៍9ងេ��មគឺ2�រប&' ញពីេw/ ះ Fileds �ំងអសែ់ដល*នេfក#ុង TableProduct

4. �រេ�����ស ់QueryDef Object:

QueryDef Object �ត�វ�នេ�ប��ស2់មួយនឹង DAO េដម�ីប&' ញkលព់័ត៌*នមួយចំនួនរបស ់Query ែដល*ន

េfក#ុង Database ។

Page 79: Advance Access 2010 Khmer

Access 2010 Advance www.enteritc.com 75

មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័ Enter Information Technology Center

Ex: ឧ�ហរណ៍9ងេ��មគឺ2�រប&' ញពីេw/ ះ Query �ំងអសែ់ដល*នេfក#ុង Database

Page 80: Advance Access 2010 Khmer

76 www.enteritc.com Microsoft Access 2010 Advance

Enter Information Technology Center មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័

5. �រេ�����ស ់RecordSet Object:

RecordSet Object �ត�វ�នេ�ប��ស2់មួយនឹង DAO េដម�ីេធ��រ�ញយកទិន#ន័យពីក#ុង Table ឬ Query មកផ�ុក

បេK| ះ}សន#េfក#ុង Memory េដម�ីេធ��របន|េfេល Form ។

Syntax: Ex:

បM� ប់មកពី�ន�ប�ស VariableRecordset េហយេMះេយង�ត�វេបកXេ�ប��សេ់�យេ�បទំរង់ Syntax 9ង េ��ម:

Syntax: > TableName *នន័យY គឺ2េw/ ះ Table ែដល VariableRecordset �ត�វ Sore ែដលេធ��រ

> SQL គឺ2 SQL Statement ែដលសរេសរេដម�ី�សង់យកទិន#ន័យពី Table មួយ

Ex:

6. រេប�ប Add Record េ�����ស ់Do While #មយួន&ង Recordset:

Dim <VariableRecordset> As DAO.Recordset

Dim rs As DAO.Recordset

Set <VariableRecordset> = <VariableRecordset>.OpenRecordset ("<TableName>|<SQL>")

Set rs = db.OpenRecordset("TableProduct")

Page 81: Advance Access 2010 Khmer

Access 2010 Advance www.enteritc.com 77

មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័ Enter Information Technology Center

7. រេប�ប Edit Record #មយួន&ង Recordset:

Page 82: Advance Access 2010 Khmer

78 www.enteritc.com Microsoft Access 2010 Advance

Enter Information Technology Center មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័

8. រេប�ប Find Record #មយួន&ង Recordset:

Page 83: Advance Access 2010 Khmer

Access 2010 Advance www.enteritc.com 79

មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័ Enter Information Technology Center

9. រេប�ប Delete Record #មយួន&ង Recordset:

Page 84: Advance Access 2010 Khmer

80 www.enteritc.com Microsoft Access 2010 Advance

Enter Information Technology Center មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័

10. �របេង(�ត Button Clear:

Page 85: Advance Access 2010 Khmer

Access 2010 Advance www.enteritc.com 81

មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័ Enter Information Technology Center

11. �របេង(�ត Button Delete All:

Page 86: Advance Access 2010 Khmer

82 www.enteritc.com Microsoft Access 2010 Advance

Enter Information Technology Center មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័

12. �របេង(�ត Navigation Record #មយួន&ង Recordset:

Page 87: Advance Access 2010 Khmer

Access 2010 Advance www.enteritc.com 83

មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័ Enter Information Technology Center

Page 88: Advance Access 2010 Khmer

84 www.enteritc.com Microsoft Access 2010 Advance

Enter Information Technology Center មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័

13. លំ)ត:់

Page 89: Advance Access 2010 Khmer

Access 2010 Advance www.enteritc.com 85

មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័ Enter Information Technology Center

េមេរ�នទ� 6: �រ�� ប ់ComboBox &

Listbox �មយួ DAO

1. �រេ!"�!#ស ់ComboBox & ListBox:

ComboBox និង ListBox គឺ� Control មួយែដលនិយមេ�ប��សេ់ដម�ីបេង�ត� Application ក�ុង�រ�គប់�គងទិន�

ន័យេ!ក�ុងកម"វធិី Microsoft Access ។ ពួក'�ត(វ�នេ�ប��សស់*ំប់ផ,ុកទិន�ន័យ�ជំេរ ស .ន�/ប់េ0យពុំ1ំ

�ច់េធ3�រប45ូ លទិន�ន័យេ0យ7, លដ់ូច� TextBox េ8ះេទ។ '.នលក:ណៈៃន�រេ�ប��ស ់�ប>ក់�បែហល

@� ប៉ុែនE ComboBox បFG ញទិន�ន័យែតមួយ Item បុ៉េJK ះ ចំែនក ListBox បFG ញ Items Nំងអសែ់ដល.ន។

េយងPចេធ3�រ Add Items េQក�ុង ComboBox ឬ ListBox Sមរយៈ មេធU�យ�េ�ចនដូច� Sម Wizard Nញ

េចញពី Table, Add Items ចូលេ0យ7, លS់ម Form ឬNញទិន�ន័យមក0ក់េ0យេ�ប��ស ់SQL Statement ។

2. ស�ក&ព� RowSourceType Property:

RowSourceType Property: គឺ� Property មួយែដលេ�បស*ំប់បFG ញពី�បេភទៃន ទិន�ន័យែដល ComboBox �ត(វ

Bound �មួយ។

ក�ុងេ8ះ RowSourceType Property .ន 3 �បេភទដូច�:

> Table/Query: .នន័យh ComboBox គឺ�ត(វ Bound �មួយនឹង Table ឬ Query Jមួយក�ុង Database

> FildList: គឺស*ំប់កំនត់ឲ ComboBox េធ3�រ Bound ឬNញយកែត FieldName េចញពី Table/Query ែត ប៉ុេJK ះ

េ0យមិនយកទិន�ន័យមកបFG ញេឡយ។

> Value List: ស*ំប់កំនត់ឲ ComboBox េធ3�រទទួលយកទិន�ន័យែដលកំនត់ឲែតប៉ុេJK ះ េ0យ'មិន Nញយក

(Unbound) ទិន�ន័យពី Table/Query េ8ះេទ។

3. ស�ក&ព� RowSource Property:

ប8, ប់ពី RowSourceType Property �នកំនត់ពីទំរង់ក�ុង�រ Nញទិន�ន័យមក0ក់ក�ុង ComboBox ឬ ListBox រចួ

*លេ់ហយ គឺ�តួ8ទីរបស ់RowSource Property វញិមEង ែដល�អ�កកំនត់ពីទិន�ន័យែដល�ត(វប4�ូ ល។

SមឧNហរណ៍�ងេ��មគឺ��របFG ញពី�រេ�ប��ស ់RowSourceTyp និង RowSource Property �មួយនឹង

ListBox:

1. េបកយក FormProduct េហយ Switch េQ�ន់ Design View >

2. យក ListBox មកគូរេ!េល Form េ0យ0ក់េ�" ះh ListBoxTableProduct េហយលបុ Label 'េ1ល >

Page 90: Advance Access 2010 Khmer

86 www.enteritc.com Microsoft Access 2010 Advance

Enter Information Technology Center មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័

3. សមូ Select េល Form Selector >

4. �តង់ Property របស ់Form ចុច Event Tab >

5. ក�ុង�បអប់ On Load សមូចុច Build Button >

6. េរ សយក Code Builder >

7. ចុច OK Button

8. ប8, ប់មកសមូសរេសរកូដ ដូច�ងេ��ម >

Page 91: Advance Access 2010 Khmer

Access 2010 Advance www.enteritc.com 87

មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័ Enter Information Technology Center

9. បិទ7, ំង Code េ1ល េហយ�តឡប់េQ�ន់ Form ប8, ប់មក Switch េQ�ន់ Form View វញិ នឹង

ទទួល�នលទ�ផលដូច�ងេ��ម

4. ស�ក&ព� Column Count Property:

Column Count Property �ត(វ�នេ�ប��សេ់ដម�ីកំនត់ពីចំនួន Field ែដល�ត(វបFG ញេ!ក�ុង ComboBox ឬ ListBox

Sមធម"Sេបេយមិនកំនត់'េ8ះ'នឹងបFG ញែត 1 Field ដំបូងប៉ុេJK ះ។

Page 92: Advance Access 2010 Khmer

88 www.enteritc.com Microsoft Access 2010 Advance

Enter Information Technology Center មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័

Ex:

5. ស�ក&ព� Column Heads Property:

Column Heads Property �ត(វ�នេ�ប��សេ់ដម�ីបFG ញេ�" ះរបស ់Field Nំងអសេ់!េល ComboBox ឬ ListBox

�មួយនឹង ទិន�ន័យែដល�ន Bound យកមកផងែដរ។

Ex:

Page 93: Advance Access 2010 Khmer

Access 2010 Advance www.enteritc.com 89

មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័ Enter Information Technology Center

6. ស�ក&ព� Column Widths Property:

Column Widths Property �ត(វ�នេ�ប��សេ់ដម�ីកំនត់ពីចំនួន Field ែដល�ត(វ�នេ!េល ComboBox ឬ ListBox

�មួយនឹង ទិន�ន័យែដល�ន Bound េ0យPកំនត់�� តទំហរំបស'់� in ឬ cm �នផងែដរ។

Ex:

Page 94: Advance Access 2010 Khmer

90 www.enteritc.com Microsoft Access 2010 Advance

Enter Information Technology Center មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័

7. �របេង(�តកម)វធ�!គប!់គង ឃុំ/ស/( ត:់

1. បេង�ត Table ចំនួន 3 និងកំនត់ Property ដូច�ងេ��ម >

2. បេង�ត Form េ�" ះ FormProvinceInfo ប8, ប់មកសមូយក Tab Control មកគូរចំនួន 4 េហយកំនត់ Property

ដូច�ងេ��ម >

> Page1 : Name = PageProvince ; Caption = Province

> Page2 : Name = PageKhan ; Caption = Khan

> Page3 : Name = PageSangkat ; Caption = Sangkat

> Page4 : Name = PageAllInfo ; Caption = AllInfo

Page 95: Advance Access 2010 Khmer

Access 2010 Advance www.enteritc.com 91

មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័ Enter Information Technology Center

3. ក�ុង PageProvince សមូកំនត់ Property ដូច�ងេ��ម >

> Label : Caption = ProvinceName

> TextBox : Name = TextProvinceName

> Button : Name = ButtonAddProvince; Caption = AddProvince

> សមូសរេសរកូដេ!�តង់ On Click Event របស ់ButtonAddProvince ដូច�ងេ��ម:

4. ក�ុង PageKhan សមូកំនត់ Property ដូច�ងេ��ម >

> Label of CoboBox : Caption = ProvinceName

> ComboBox : Name = ComboBoxProvinceNameInKhan

> Label of TextBox : Caption = KhanName

> TextBox : Name = TextKhanName

> Button : Name = ButtonAddKhan ; Caption = AddKhan

Page 96: Advance Access 2010 Khmer

92 www.enteritc.com Microsoft Access 2010 Advance

Enter Information Technology Center មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័

> សមូសរេសរកូដេ!�តង់ On Load របស ់Form និង�តង់ On Click Event របស ់ButtonAddKhan

ដូច�ងេ��ម:

4. ក�ុង PageSangkat សមូកំនត់ Property ដូច�ងេ��ម >

> Label of CoboBox : Caption = ProvinceName

> ComboBox : Name = ComboBoxProvinceNameInKhan

> Label of TextBox : Caption = KhanName

> TextBox : Name = TextKhanName

> Button : Name = ButtonAddKhan ; Caption = AddKhan

Page 97: Advance Access 2010 Khmer

Access 2010 Advance www.enteritc.com 93

មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័ Enter Information Technology Center

> សមូ បែន�មកូដេ!�តង់ On Load របស ់Form ដូច�ងេ��ម:

> សមូ សរេសរកូដេ!�តង់ AfterUpdate របស ់ComboBoxProvinceNameInSangkat ដូច�ងេ��ម:

> សមូសរេសរកូដេ!�តង់ On Click របស ់ButtonAddSangkat ដូច�ងេ��ម:

5. ក�ុង PageAllInfo សមូកំនត់ Property ដូច�ងេ��ម >

> Label of CoboBox : Caption = ProvinceName

> ComboBox : Name = ComboBoxProvinceNameAllInfo

> Label of ListBox1 : Caption = KhanName

> ListBox1 : Name = ListBoxKhanNameAllInfo

Page 98: Advance Access 2010 Khmer

94 www.enteritc.com Microsoft Access 2010 Advance

Enter Information Technology Center មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័

> Label of ListBox2 : Caption = SangkatName

> ListBox2 : Name = ListBoxSangkatNameAllInfo

> សមូសរេសរកូដេ!�តង់ On Load របស ់Form ដូច�ងេ��ម:

> សមូសរេសរកូដេ!�តង់ AfterUpdate របស ់ComboBoxProvinceNameAllInfo ដូច�ងេ��ម:

> សមូសរេសរកូដេ!�តង់ AfterUpdate របស ់ListBoxKhanNameAllInfo ដូច�ងេ��ម:

Page 99: Advance Access 2010 Khmer

Access 2010 Advance www.enteritc.com 95

មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័ Enter Information Technology Center

6. �ងេ��មេនះ�លទ�ផលែដលទទួល�ន

Page 100: Advance Access 2010 Khmer

96 www.enteritc.com Microsoft Access 2010 Advance

Enter Information Technology Center មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័

Page 101: Advance Access 2010 Khmer

Access 2010 Advance www.enteritc.com 97

មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័ Enter Information Technology Center

េមេរ�នទ� 7: �រេ�����ស ់

Keyword Execute ក�ុង DAO

1. ន�យមនយ័:

Execute គឺ� Keyword ែដល�តវ�នេ�ប��សេ់�ក�ុង DAO េដម�ីេធ��រប�! ឲដំេន�រេ$េល action query

%មួយ ឬេដម�ីប�! ឲ Query Run េដម�ីដំេន�រ�រ)រអ�ីមួយ។

Syntax: > vardatabase :គឺ� Variable ែដល,ន�បេភទ� DAO.database

> sqlstatements :គឺ� SQL Statement ស0ំប់ប�! ឲេធ��រ �រ)រ%មួយ Ex: 1. សមូបេង3ត Form មួយែដល,ន Property ដូច5ងេ��ម >

2. សមូសរេសរកូដេ�ក�ុង ButtonAdd ដូច5ងេ��ម:

Vardatabase.Execute sqlstatements

Page 102: Advance Access 2010 Khmer

98 www.enteritc.com Microsoft Access 2010 Advance

Enter Information Technology Center មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័

2. ឧ%ហរណៃ៌ន�រេ�����ស ់Excute:

7មឧ9ហរណ៍5ងេ��មនឹងប)@ ញពី�រេ�ប��ស ់Execute �មួយនឹង�របេង3ត Form Student Change Class

ដូេច�ះសមូអនុវតJ7មជំNនដូច5ងេ��ម:

1. សមូបេង3ត TableStudents មួយែដល,នទំរង់ដូច5ងេ��ម >

2. សមូបUWូ នទិន�ន័យេ$ក�ុង Table ដូច5ងេ��ម >

Page 103: Advance Access 2010 Khmer

Access 2010 Advance www.enteritc.com 99

មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័ Enter Information Technology Center

3. សមូបេង3ត Form ែដល,នទំរង់ែដល,នទំរង់ដូច5ងេ��ម >

4. សមូសរេសរកូដេ�ក�ុង Form_Load ដូច5ងេ��ម >

Private Sub Form_Load() Me.ComboBoxFromGroup.RowSource = "Select Distinct Group from TableStudents" Me.ComboBoxToGroup.RowSource = "Select Distinct Group from TableStudents" Me.ComboBoxFromClass.RowSource = "Select Distinct Class from TableStudents" Me.ComboBoxToClass.RowSource = "Select Distinct Class from TableStudents" Me.ListBoxFromClass.ColumnCount = 2 Me.ListBoxFromClass.ColumnHeads = True Me.ListBoxFromClass.ColumnWidths = "1 in;1 in" Me.ListBoxToClass.ColumnCount = 2 Me.ListBoxToClass.ColumnHeads = True Me.ListBoxToClass.ColumnWidths = "1 in;1 in" End Sub

Page 104: Advance Access 2010 Khmer

100 www.enteritc.com Microsoft Access 2010 Advance

Enter Information Technology Center មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័

5. សមូសរេសរកូដេ�ក�ុង ComboBoxFromGroup_AfterUpdate ដូច5ងេ��ម >

6. សមូសរេសរកូដេ�ក�ុង ComboBoxFromClass_AfterUpdate ដូច5ងេ��ម >

7. សមូសរេសរកូដេ�ក�ុង ComboBoxToGroup_AfterUpdate ដូច5ងេ��ម >

Private Sub ComboBoxToGroup_AfterUpdate() Dim sqls As String sqls = "SELECT TableStudents.StudentID, TableStudents.Name, TableStudents.Group FROM TableStudents WHERE TableStudents.Group ='" & Me.ComboBoxToGroup & "'" Me.ListBoxToClass.RowSource = sqls End Sub

Private Sub ComboBoxFromClass_AfterUpdate() Me.ListBoxFromClass.RowSource = "Select StudentID,Name from TableStudents where Class ='" & Me.ComboBoxFromClass & "'" End Sub

Private Sub ComboBoxFromGroup_AfterUpdate() Dim sqls As String sqls = "SELECT TableStudents.StudentID, TableStudents.Name, TableStudents.Group FROM TableStudents WHERE TableStudents.Group ='" & Me.ComboBoxFromGroup & "'" Me.ListBoxFromClass.RowSource = sqls End Sub

Page 105: Advance Access 2010 Khmer

Access 2010 Advance www.enteritc.com 101

មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័ Enter Information Technology Center

8. សមូសរេសរកូដេ�ក�ុង ComboBoxToClass_AfterUpdate ដូច5ងេ��ម >

9. សមូសរេសរកូដេ�ក�ុង ButtonAddRight_Click ដូច5ងេ��ម >

Private Sub ButtonAddRight_Click() Dim db As DAO.Database Dim i As Long Dim id As Long Set db = CurrentDb For i = 0 To Me.ListBoxFromClass.ListCount - 1 If Me.ListBoxFromClass.Selected(i) = True Then id = Me.ListBoxFromClass.Column(0, i) End If Next i db.Execute "Update TableStudents set TableStudents.Class='" & Me.ComboBoxToClass.Value & "',TableStudents.Group='" & Me.ComboBoxToGroup.Value & "' " & " where StudentID = " & id Me.ListBoxFromClass.Requery Me.ListBoxToClass.Requery End Sub

Private Sub ComboBoxToClass_AfterUpdate() Me.ListBoxToClass.RowSource = "Select StudentID,Name from TableStudents where Class ='" & Me.ComboBoxToClass & "'" End Sub

Page 106: Advance Access 2010 Khmer

102 www.enteritc.com Microsoft Access 2010 Advance

Enter Information Technology Center មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័

10. សមូសរេសរកូដេ�ក�ុង ButtonAddLeft_Click ដូច5ងេ��ម >

Private Sub ButtonAddLeft_Click() Dim db As DAO.Database Dim i As Long Dim id As Long Set db = CurrentDb For i = 0 To Me.ListBoxToClass.ListCount - 1 If Me.ListBoxToClass.Selected(i) = True Then id = Me.ListBoxToClass.Column(0, i) End If Next i db.Execute "Update TableStudents set TableStudents.Class='" & Me.ComboBoxFromClass.Value & "',TableStudents.Group='" & Me.ComboBoxFromGroup.Value & "' " & " where StudentID = " & id Me.ListBoxFromClass.Requery Me.ListBoxToClass.Requery End Sub

Page 107: Advance Access 2010 Khmer

Access 2010 Advance www.enteritc.com 103

មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័ Enter Information Technology Center

េមេរ�នទ� 8: �របេង��តកម��ធ��គប�់គង Stock (Stock Management System)

1. ន�យមនយ័:

Stock Management System គឺ�កម�វធិីែដល�ត�វ�នបេង�តេ�យ Microsoft Access ែដល��នតួ�ទីកត់�"ពី

Product ែដល�ន Import និង Product ែដល�ន Export េហយប%& ញពី Balance របស ់Product ែដល�នេ*ក+ុង

Stock -ំងអស។់

តំរវូ2ររបស�់គឺ�ត�វបេង�ត Table ចំនួន 3 ែដល�នដូច�:

> TableImport

> TableStock

> TableExport

ក+ុងេ�ះក�៏ត�វបេង�ត Form ចំនួន 3 ដូច7+ ផងែដរ ែដល�នេ9� ះដូច�:

> FormImport

> FormExport ។

2. �របេង��ត Table:

1. សមូបេង�ត TableImport េ�យកំនត់ Property ដូច=ងេ�2ម >

2. សមូបេង�ត TableStock េ�យកំនត់ Property ដូច=ងេ�2ម >

3. សមូបេង�ត TableExport េ�យកំនត់ Property ដូច=ងេ�2ម >

Page 108: Advance Access 2010 Khmer

104 www.enteritc.com Microsoft Access 2010 Advance

Enter Information Technology Center មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័

3. �របេង��ត FormImport:

1. សមូបេង�ត FormImport េ�យកំនត់ Property ដូច=ងេ�2ម >

2. សមូសរេសរកូដ េ*�តង់ ButtonAdd_Click ដូច=ងេ�2ម >

Option Compare Database Private Sub ButtonAdd_Click() Dim db As DAO.Database Dim rs As DAO.Recordset Set db = CurrentDb Set rs = db.OpenRecordset("TableImport") With rs .AddNew !ProductNumber = Me.TextProductNumber !ProductName = Me.TextProductName !ImportDate = Me.DTPickerImport !quantity = Me.TextQuantity .Update .Close End With If checkstock(Me.TextProductNumber) = True Then Call updatestock(Me.TextProductNumber, Me.TextQuantity) Else Call AddNewStock(Me.TextProductNumber, Me.TextProductName, Me.TextQuantity) End If MsgBox ("Import Successful") End Sub

Page 109: Advance Access 2010 Khmer

Access 2010 Advance www.enteritc.com 105

មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័ Enter Information Technology Center

Public Sub updatestock(pid As Integer, ByVal qty As Long) Dim db As DAO.Database Dim rs As DAO.Recordset Set db = CurrentDb Set rst = db.OpenRecordset("TableStock", dbOpenDynaset) With rst Do While !ProductNumber <> pid .MoveNext Loop .Edit !quantity = !quantity + qty .Update .Close End With End Sub

Public Function checkstock(ByVal p As Integer) As Boolean Dim db As DAO.Database Dim rst As DAO.Recordset Set db = CurrentDb Set rst = db.OpenRecordset("TableStock") With rst Do While Not .EOF If !ProductNumber = p Then checkstock = True Exit Do Else .MoveNext End If Loop .Close End With End Function

Page 110: Advance Access 2010 Khmer

106 www.enteritc.com Microsoft Access 2010 Advance

Enter Information Technology Center មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័

4. �របេង��ត FormExport:

1. សមូបេង�ត FormExport េ�យកំនត់ Property ដូច=ងេ�2ម >

2. សមូសរេសរកូដ េ*�តង់ ButtonSubtract_Click ដូច=ងេ�2ម >

Public Sub AddNewStock(ByVal pid As Integer, ByVal pr As String, ByVal qt As Long) Dim db As DAO.Database Dim rst As DAO.Recordset Set db = CurrentDb Set rst = db.OpenRecordset("TableStock", dbOpenDynaset) With rst .AddNew !ProductNumber = pid !ProductName = pr !quantity = qt .Update .Close End With End Sub

Page 111: Advance Access 2010 Khmer

Access 2010 Advance www.enteritc.com 107

មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័ Enter Information Technology Center

Public Function checkstock(ByVal p As Integer) As Boolean Dim db As DAO.Database Dim rst As DAO.Recordset Set db = CurrentDb Set rst = db.OpenRecordset("TableStock") With rst Do While Not .EOF If !ProductNumber = p Then checkstock = True Exit Do Else .MoveNext End If Loop .Close End With End Function

Option Compare Database Private Sub ButtonSubtract_Click() If checkstock(Me.TextProductNumber) = True Then Call updatestock(Me.TextProductNumber, Me.TextQuantity) Dim db As DAO.Database Dim rs As DAO.Recordset Set db = CurrentDb Set rs = db.OpenRecordset("TableExport") With rs .AddNew !ProductNumber = Me.TextProductNumber !ProductName = Me.TextProductName !ExportDate = Me.DTPickerExport !quantity = Me.TextQuantity .Update .Close End With MsgBox ("Export Successful!") Else MsgBox ("This Product doesn't have in stock!") End If End Sub

Page 112: Advance Access 2010 Khmer

108 www.enteritc.com Microsoft Access 2010 Advance

Enter Information Technology Center មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័

5. លំ$ត:់

1. ចូរបេង�ត FormStock មួយដូច=ងេ�2ម:

Public Sub updatestock(pid As Integer, ByVal qty As Long) Dim db As DAO.Database Dim rs As DAO.Recordset Set db = CurrentDb Set rst = db.OpenRecordset("TableStock", dbOpenDynaset) With rst Do While !ProductNumber <> pid .MoveNext Loop .Edit !quantity = !quantity - qty .Update .Close End With End Sub

Page 113: Advance Access 2010 Khmer

Access 2010 Advance www.enteritc.com 109

មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័ Enter Information Technology Center

េមេរ�នទ� 9: រេប�ប Search ទ�ន�នយ័េ�ក�ុង (Stock Management System)

1. �របេង!�ត Form:

1. សមូបេង�ត FormStock េហយេរ�បចំ property ដូច�ងេ��ម >

2. សមូសរេសរកូដេ�ក�ុង Form_Load ដូច�ងេ��ម >

Option Compare Database Private Sub Form_Load() Me.OptionSearchImport.Value = 1 Me.OptionSearchExport.Value = 1 Dim db As DAO.Database Dim rs1, rs2, rs3 As DAO.Recordset Set db = CurrentDb Set rs1 = db.OpenRecordset("TableImport") Me.ListBoxImport.ColumnHeads = True Me.ListBoxImport.ColumnCount = 4 Me.ListBoxImport.RowSource = "Select * from TableImport" Set rs2 = db.OpenRecordset("TableStock") Me.ListBoxProducts.ColumnHeads = True Me.ListBoxProducts.ColumnCount = 3 Me.ListBoxProducts.RowSource = "Select * from TableStock"

Page 114: Advance Access 2010 Khmer

110 www.enteritc.com Microsoft Access 2010 Advance

Enter Information Technology Center មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័

3. សមូសរេសរកូដេ�ក�ុង ButtonSearchImport_Click ដូច�ងេ��ម >

4. សមូសរេសរកូដេ�ក�ុង ButtonSearchExport_Click ដូច�ងេ��ម >

Private Sub ButtonSearchImport_Click() Dim db As DAO.Database Dim rs As DAO.Recordset Set db = CurrentDb Set rs = db.OpenRecordset("TableImport") Me.ListBoxImport.ColumnHeads = True Me.ListBoxImport.ColumnCount = 4 If Me.OptionSearchImport.Value = 1 Then Me.ListBoxImport.RowSource = "Select * from TableImport WHERE ProductNumber =" & Me.TextSearchByID & "" Else Me.ListBoxImport.RowSource = "Select * from TableImport WHERE ImportDate Between #" & Format(Me.FromImport, "mm/dd/yyyy") & "# AND #" & Format(Me.ToImport, "mm/dd/yyyy") & "#" End If End Sub

Set rs3 = db.OpenRecordset("TableExport") Me.ListBoxExport.ColumnHeads = True Me.ListBoxExport.ColumnCount = 4 Me.ListBoxExport.RowSource = "Select * from TableExport" End Sub

Page 115: Advance Access 2010 Khmer

Access 2010 Advance www.enteritc.com 111

មជ�មណ� លពត័�៌ន�ទ�អ�នធរ័ Enter Information Technology Center

Private Sub ButtonSearchExport_Click() Dim db As DAO.Database Dim rs As DAO.Recordset Set db = CurrentDb Set rs = db.OpenRecordset("TableExport") Me.ListBoxImport.ColumnHeads = True Me.ListBoxImport.ColumnCount = 4 If Me.OptionSearchExport.Value = 1 Then Me.ListBoxExport.RowSource = "Select * from TableExport WHERE ProductNumber =" & Me.TextSearchByIDExport & "" Else Me.ListBoxExport.RowSource = "Select * from TableExport WHERE ExportDate Between #" & Format(Me.FromDateExport, "mm/dd/yyyy") & "# AND #" & Format(Me.ToDateExport, "mm/dd/yyyy") & "#" End If End Sub