You are on page 1of 115



  ! $ & ' ()


*

/ 0135 7 / 9 ;?@
; A ;;&  DFG7 H
& @I

J9 F  3& MN O PRF  D


S &H J U N
U &F  1 1 &
V F && FG7W5
&

1 1 &V; V (  0
PR  U N
U J5&Y Z@ !!
M &YY

\&]] PRF  ^ H 1 1
&V; ;M
`F&N \
a &&F  JU
&VG]
M

A&]]
PRF 


:

&

:

&

  :

&
9c d

#$%:'

&
9c d
U
e

(( :

Vd ! 2013 ' PRF  M ( 9 &


Ha&N]k D ;N' 3Ha
)n5o1 Fpa
d

*+:
9 179 Z 173 /S R Mc&
Tel: 010-011-012-016 603 314
Website: www.enteritc.com | facebook.com/enteritc

,-.
] 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: Sa Stock ................................................................................................................................. 103
] 9: ] search &3& Stock .......................................................................................................................... 111

02,
%5

Enter Information Technology Center

( 1: .89( SQL Statement


(Structure Query Language)

1. :
SQL 7( D J &@oR D 'Fo
Query   p &,
&, & UI &'
 command Query &'  Wizard
I7(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 >

Access 2010 Advance

www.enteritc.com

02,
%5

Enter Information Technology Center

4. View Arrow >


5. SQL View >

6. & Query $ >

select StudentID,FullName,Gender,Class
from TableStudentList
where StudentID > 4
order by FullName ASC;

7. Run >

8. $ d

www.enteritc.com

Microsoft Access 2010 Advance

02,
%5

Enter Information Technology Center

3. .>(? Select Statement:


Select Statement  SQL Statement J Select & Table @oR D
Syntax:

Select <FieldName1,[FieldName2,]>
from <TableName>
Where <Condition>
Order By <FieldName> ASC|DESC;
Example:
;$ /*  Select Statement ':
> StudentID, FullName, Gender, Class
> TableStudentList
> StudentID ;N 4
> ]& D/*'
SQL Statement:

select StudentID,FullName,Gender,Class
from TableStudentList
where StudentID > 4
order by FullName ASC;
Output:

Access 2010 Advance

www.enteritc.com

02,
%5

Enter Information Technology Center


4. .>(? Select Top Statement:

Select Top Statement  SQL Statement J Select & Table @oR


Records D
Syntax:

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


from <TableName>
Where <Condition>
Order By <FieldName> ASC|DESC;
Example:
;$ /*  Select Statement ':
> StudentID, FullName, Gender, Class 2 records
> TableStudentList
> StudentID ;N 4
> ]& D/*'
SQL Statement:

select Top 2 StudentID,FullName,Gender,Class


from TableStudentList
where StudentID > 4
order by FullName ASC;
Output:

www.enteritc.com

Microsoft Access 2010 Advance

02,
%5

Enter Information Technology Center

5. .>(? Select and Join On Statement:


Select and Join On Statement  SQL Statement J Select & Table F
Relationship H&'&YI?@oR 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:

Select TableStudentList.StudentID,FullName,
Gender, Points
From TableStudentList Inner join TableStudyList
On TableStudentList.StudentID =
TableStudyList.StudentID
Where TableStudentList.StudentID > 4
Order by FullName;

Output:

Access 2010 Advance

www.enteritc.com

02,
%5

Enter Information Technology Center

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;

www.enteritc.com

Microsoft Access 2010 Advance

02,
%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;

Access 2010 Advance

www.enteritc.com

02,
%5

Enter Information Technology Center


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

www.enteritc.com

Microsoft Access 2010 Advance

02,
%5

Enter Information Technology Center

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;

Output:

( 2:
SQL Statement:

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;

Access 2010 Advance

www.enteritc.com

02,
%5

Enter Information Technology Center


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:

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;

Output:

10

www.enteritc.com

Microsoft Access 2010 Advance

02,
%5

Enter Information Technology Center

11. .>(? SQL Statement AB(C( Crosstab Query:


SQL Statement:

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;
Output:

12. .>(? Insert Statement:


Insert Statement  SQL Statement J p &@& Table @oR D

Syntax:

Insert Into <TableName>


Value <Values>
Example:
;$ /*  Insert Statement ':
> Field StudentID p 20
> FullName p Chea Phalla
> Gender p 'Female'
> Class p '10E'

Access 2010 Advance

www.enteritc.com

11

02,
%5

Enter Information Technology Center


SQL Statement:

Insert Into
TableStudentList(StudentID,FullName,Gender,Class)
Values(20,'Chea Phalla','Female','10E')
Output:

13. .>(? Update Statement:


Update Statement  SQL Statement J &@& Table @oR D
Syntax:

Update <TableName>
Set <FieldName> = <value>
Where condition
Example:
;$ /*  Insert Statement ':
> Field StudentID p 20
> FullName p Chea Phalla
> Gender p 'Female'
> Class p '10E'

12

www.enteritc.com

Microsoft Access 2010 Advance

02,
%5

Enter Information Technology Center

SQL Statement:

UPDATE TableStudentList
SET StudentID = 15, FullName = 'Lim Kevtheara',
Class = '10B'
WHERE StudentID =20;
Output:

14. 

( Table D* Table :
Example:
;$ /* &0 Record 6 @F StudentID,
FullName, Gender, Class TableStudentList @'3& Table 1]S
a TableStudentList2
SQL Statement:

Insert Into
TableStudentList2(StudentID,FullName,Gender,Class)
Select StudentID,FullName,Gender,Class
From TableStudentList Where StudentID > 5
Output:


( Table DC(E Table GA :
15. 
Example:
;$ /* &0 Record 6 @F StudentID,
FullName, Gender, Class TableStudentList @'3& Table a] a TableStudentList3
DS'  SQL Statement

Access 2010 Advance

www.enteritc.com

13

02,
%5

Enter Information Technology Center


SQL Statement:

Select StudentID, FullName, Gender, Class Into


TableStudentList3
From TableStudentList2
Where StudentID >5
Output:

16. C( Table:
SQL Statement:

CREATE TABLE Student


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

Output:

17.  Field Table:


Syntax:

Alter Table <TableName>


Add Column <FieldName DataType>
Example:
;$ /* G Field 2 @ TableStudentList2 Field 1 a
PhoneNumber F DataType  Text Field 2 a Payment F DataType  Currency

14

www.enteritc.com

Microsoft Access 2010 Advance

02,
%5

Enter Information Technology Center

SQL Statement:

Alter Table TableStudentList2


Add Column PhoneNumber Text(20), Payment Single

18. Field ( Table:


Syntax:

Alter Table <TableName>


Drop Column <FieldName>
Example:
;$ /* Field 2 TableStudentList2 Field 1 a
PhoneNumber Field 2 a Payment
SQL Statement:

Alter Table TableStudentList2


Drop Column PhoneNumber, Payment

19. Record ( Table:


Syntax:

Delete from <TableName>


Where <condition>
Example:
;$ /* Record StudentID 15 TableStudentList

SQL Statement:

Delete from TableStudentList


Where StudentID = 15

Access 2010 Advance

www.enteritc.com

15

02,
%5

Enter Information Technology Center


Output:

20. Table:
Example:
;$ /* TableStudentList2 Database
SQL Statement:

Drop Table TableStudentList2

21. .>(? Union:


Union D J Select Record  Table  1H&
Example:
;$ /* TableStudentList2 Database
SQL Statement:

Select StudentID,FullName,Gender,Class From


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

Output:

16

www.enteritc.com

Microsoft Access 2010 Advance

02,
%5

Enter Information Technology Center

22. .>(? Sub Query:


Sub Query  SQL Statement J &@oR d Query
1]
Syntax:

Select <FieldNameI> From <TableNameI>


Where <ConditionI> IN|NOT IN (
Select <FieldNameII> from <TableNameII>
where <ConditionII> );

SQL Statement:

Select StudentID,FullName,Gender,Class From


TableStudentList
Where StudentID in (
Select StudentID from TableStudentList
where StudentID=5);
Output:

Access 2010 Advance

www.enteritc.com

17

02,
%5

Enter Information Technology Center

18

www.enteritc.com

Microsoft Access 2010 Advance




Enter Information Technology Center

 2: 
!" Macro

1. :
Macro  Object Microsoft Access  Database
!" Button Menu &( ) + Form &,,-./
137, 9 Macro <= Autoexe ?
FormMainboardButton !@
,G Database
1.  FormMainboardButton ! Create Tab >
2. Form Design >

3. Save Button !<=QR FormMainboardButton /./QU >

4. Create Tab >


5. Macro >

6. , Add New Action , OpenForm >

Access 2010 Advance

www.enteritc.com

19




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 |

20

www.enteritc.com

Microsoft Access 2010 Advance




Enter Information Technology Center

2. ( Open Button:


137, 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 >

Access 2010 Advance

www.enteritc.com

21




Enter Information Technology Center

9. Run Button |

3. ( Close Button:


137, 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 >

22

www.enteritc.com

Microsoft Access 2010 Advance




Enter Information Technology Center

4. )* Macro + - Form:


137,3 Macro <= MacroOpenTableStudentList
MacroCloseFormStudentList ? FormStudentList  Button & Form ,,- 1.
FormStudentList View >
2. Design View >

3. U3 MacroCloseFormStudent MacroOpenTableStudentList ?1,] >

Access 2010 Advance

www.enteritc.com

23




Enter Information Technology Center

4. View >
5. Design View

.
/ Macro:
5. 
137,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 >
24

www.enteritc.com

Microsoft Access 2010 Advance




Enter Information Technology Center

9. Create Tab >


10. Macro Button >

11. ,
Q OpenForm >

12. , Form Name FormStudentList >


13. , View Form >
14. , 7G, Where Condition Build Button >

15. 7,? , >


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

Access 2010 Advance

www.enteritc.com

25




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 Q9./ Wizard >

26

www.enteritc.com

Microsoft Access 2010 Advance




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 Q9./ Wizard >

Access 2010 Advance

www.enteritc.com

27




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

28

www.enteritc.com

Microsoft Access 2010 Advance




Enter Information Technology Center

6. )* Macro + - ComboBox:


137,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 QU >

Access 2010 Advance

www.enteritc.com

29




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 >

30

www.enteritc.com

Microsoft Access 2010 Advance




Enter Information Technology Center

17. ,
!<=R FormCustomer >
18. Finish Button QU >

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] >

Access 2010 Advance

www.enteritc.com

31




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 >

32

www.enteritc.com

Microsoft Access 2010 Advance




Enter Information Technology Center

32. Cancel Button >

33. Label ComboBox Find ID >


34. , Properties , Name !<= Cust-ID >

35. Data Tab >


36. , Row Source QueryCustomerIDAndName >

Access 2010 Advance

www.enteritc.com

33




Enter Information Technology Center

37. Event Tab >


38. , After Update MacroFindRecord >

39. Save Button >


40. View >
41. Design View >

34

www.enteritc.com

Microsoft Access 2010 Advance




Enter Information Technology Center

42. /-|7,

Access 2010 Advance

www.enteritc.com

35




Enter Information Technology Center

36

www.enteritc.com

Microsoft Access 2010 Advance




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) -@KL1 Form Report KLN
> Public (Global Module) -. Public Module @@ Objects  Database
@UX
L Code -1!!? Objects  Database
3. Procedure:
Procedure  N Statement .@ Code VBA X 44\/
124 @ 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 KLN
4.  Event Procedure:
27~4\g4 VBA Code | Button ) FormBiography
1. FormBiography  DesignView >
2. Button  Form >

Access 2010 Advance

www.enteritc.com

37




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 >

38

www.enteritc.com

Microsoft Access 2010 Advance




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 )_ >

Access 2010 Advance

www.enteritc.com

39




Enter Information Technology Center

14. ~4_!

5.  Pre-Build Function:


Pre-Build Function  Function ; Microsoft Access KLN
~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


40

www.enteritc.com

Microsoft Access 2010 Advance



> Len(string)

Enter Information Technology Center

: Xw; String

> Left(String,n) : 4w@^1


> Mid(string,start,n) : 4w1224
> Right(string,n) : 4w@N 1^
> Ucase(string) : X1w7
> Lcase(string) : X1w7
> Trim(string)

: X
Space ~~4

6.  Function !
Public Procedure:
27~4\g4. Function Capfirst U; 4

Convert w1w
1. Create Tab >
2. Module >

3. VBA Code ~4 >

4. Save Button @ ModuleUtilities >


5. OK Button KLU >

6. FormCustomer  Design View Select TextBox Name >


7.  Property Sheet  Control Source Build Button >

Access 2010 Advance

www.enteritc.com

41




Enter Information Technology Center

8.  Expression Builder >


= Capfirst( Form![Name] )

9.  Name N 1 Names Save Button >

42

www.enteritc.com

Microsoft Access 2010 Advance




Enter Information Technology Center

10. Switch 14 Form View !_~4

7. #$#% Comment:
4 Program ^ Dw  Code Statement )
|
\ @U!4 Comment !@@
( ' ) Apostrophe ~ Statement  Comment
Ex:

8. #$#% Statement:
4 VBA Access Statement wL 
4L (Enter Key)  Statement !;L; Error

Ex:

Access 2010 Advance

www.enteritc.com

43




Enter Information Technology Center

4L  Statement @; Error 


 Underscore ~ ?4L
Ex:

)^4 Statement  ! Colon (: )


Ex:

44

www.enteritc.com

Microsoft Access 2010 Advance




Enter Information Technology Center

9. '!

*+ Elements:

)4@ Elements  Sub Procedures, Function Procedures, Variable,


D2D4!:
1. N@w (Letter)
2. L-w, Underscore
3. ? !
4. ! (Reserved Keyword)
5. 40 w

Reserved Keyword 
VBA Code !KL
? )
| 14 4\
// Reserved Keyword ; If, Loop, Len, Mid, Close, Or, Mod,

10.  Variable:


Variable ?X= Memory U X!
 Memory 4! Variable ^44U L-N

1U !U4

Syntax:
Dim VariableName [As Type]

> Dim  Keyword X!)] 4. Variable


> VariablName  Variable .@D2)4 Element
> As  Keyword X] 4.

Data Type
> Type   (Data Type) Variable 1!

 Data Type U Data Type  Variant 1 Variable

Ex:
Dim
Dim
Dim
Dim
Dim
Dim

Access 2010 Advance

Result As Integer
Discount As Double
Birthdate As Variant
Name As String
Temp
Temp As Variant

www.enteritc.com

45




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: 27~4 Varible x Variable Temp  Implici Declaration ;-
U!@! Declare 

> Explicit Declaration ! Variable @! Declare U!24


 @~? Option Explicit  Delcarations Section
Ex: 27~4 Option Explicit ! Delcarations Section  Variable
Temp @~ Declare !U

46

www.enteritc.com

Microsoft Access 2010 Advance




Enter Information Technology Center

12.  Data Type:


Data Type  Varible   Declare Variable
 Data Type 1U!  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

4 byte

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

4 byte

-3.2823E38 to -1.401298E-308 to

(long integer)
Single
( double-precision

-494065645841247E-324 for negative values,

floating-point)

4.94065645841247E-324 to 1.79769313486232E308
For positive values,

Currency

8 byte

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

( scaled integer)
Decimal

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

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

10 bytes +

0 to approximately 2 billion

(variable-length)

String length

String

Length of string

10 to approximately 65,400

16 byte

Any numeric value up to the range of a Double

Variant

22 byte +

Same range as for variable-length String

(with characters)

String length

User-defined

Number

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

(using Type)

Required by

type.

(fixed-length)
Variant
(with numbers)

elements

Access 2010 Advance

www.enteritc.com

47




Enter Information Technology Center


13. Variable & Data Type Pratical:

27~4\g4.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 >

48

www.enteritc.com

Microsoft Access 2010 Advance




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 >

Access 2010 Advance

www.enteritc.com

49




Enter Information Technology Center

13. VBA Code ~4 L Save U >

14. 4 Form Design Save @@ FormVariablePratical >


15. OK Button >

16. Button  ButtonSum Cancel \gKL Wizard >

17.  Properties  Name @ ButtonClear >


18.  Caption Clear >

50

www.enteritc.com

Microsoft Access 2010 Advance




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 >

Access 2010 Advance

www.enteritc.com

51




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/

52

www.enteritc.com

Microsoft Access 2010 Advance




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 @-U1! ButtonSum
! -!  ButtonClear !

Access 2010 Advance

www.enteritc.com

53




Enter Information Technology Center

> Global (Public):  Variable ! Public declare  General Declaration Section
( Module ) @U-!!  Procedures  Module !
Ex: Variable msg ! declare  ModuleGlobal U-!?7

54

www.enteritc.com

Microsoft Access 2010 Advance




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

Access 2010 Advance

www.enteritc.com

55




Enter Information Technology Center

> Static Variable  Variable =/


N - N ! U
Clear ;  !4
Ex:  Lable -X! ButtonClick - Variable i  Static
Variable

56

www.enteritc.com

Microsoft Access 2010 Advance




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 GI
Skip 4 Block Code 8 Block Code G2 ?@ Message 1 Fail
 K Condition Structure 
KN Query, Form, Report, SQL Statement,
T   VBA U2F
Codtion Structures W:
> If Then
> If Then Else
> Select Case

> Loop Structure  Code ! Code +


-: 0 Loop Structure ! 2
[  FF 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>

Access 2010 Advance

www.enteritc.com

57




Enter Information Technology Center


Example:

Syntax Multiple Statment:

If <Condition> Then
<Statement>
End If

58

www.enteritc.com

Microsoft Access 2010 Advance




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
Access 2010 Advance

www.enteritc.com

59




Enter Information Technology Center


Example:

60

www.enteritc.com

Microsoft Access 2010 Advance




Enter Information Technology Center

4. Select Case Condition Structure:


Select Case 
 ! Block of Statements 8^&) True G
&)
4 8v If Then Else
Syntax:

Select Case <TestExpression>


Case <Expression-1>
<Statement-1>
Case <Expression-2>
<Statement-2>
Case <Expression-n>
<Statement-n>
Case Else
<Statement-Else>
End Select
Example 1:

Access 2010 Advance

www.enteritc.com

61




Enter Information Technology Center

`
Example 2:

62

www.enteritc.com

Microsoft Access 2010 Advance




Enter Information Technology Center

5. Do Loop While Structure:


Do Loop While 
 ! Block of Statement  x&)
G Do Loop While I Block of Statement {|&)
^  &) GIF< F&) I4
Loop
Syntax:

Do
<Statements>
Loop while <Condition>
Example:

Access 2010 Advance

www.enteritc.com

63




Enter Information Technology Center

G Do Loop Until 0 F !{|1 G2 Block of Statement


FGI{|&)  &) GIF< &)
I4 Loop
Syntax:

Do
<Statements>
Loop while Until <Condition>
Example:

6. Do While Loop Structure:


Do While Loop 
 ! Block of Statement  x&)
G Do While Loop I{|&)  &) GI
 Loop F&) I4 Loop

64

www.enteritc.com

Microsoft Access 2010 Advance




Enter Information Technology Center

Syntax:

Do While <Condition>
<Statements>
Loop

While <Condition>
<Statements>
Wend

Example:

G Do Until 0 F !{|&)  &) GI


 Loop &)I4 Loop
Syntax:

Do while Until <Condition>


<Statements>
Loop

Access 2010 Advance

www.enteritc.com

65




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>

66

www.enteritc.com

Microsoft Access 2010 Advance




Enter Information Technology Center

Example:

Access 2010 Advance

www.enteritc.com

67




Enter Information Technology Center


8.  Radio Button:

68

www.enteritc.com

Microsoft Access 2010 Advance




Enter Information Technology Center

9.  CheckBox:

Access 2010 Advance

www.enteritc.com

69




Enter Information Technology Center

11. ":

70

www.enteritc.com

Microsoft Access 2010 Advance




Enter Information Technology Center

 5:  DAO

(Data Access Object)


1. Control Execution:
DAO  access  Database Table, Query  #
&' Form , #)* # -#/ #)
2
49&' DAO < = # FormProduct 
TableProduct
1. B TableProduct 49 >

2. B FormProduct 49 >

3. VBA Code 9 >

Access 2010 Advance

www.enteritc.com

71




Enter Information Technology Center

2.  Database Object:


 access  Database KM Variable *2 DAO.Database 2
#MS4 Syntax 9:
Syntax:

Dim <VariableDatabase> As DAO.Database


Ex:

Dim db As DAO.Database

M VariableDatabase MX Syntax 9:


Syntax:

Set <VariableDatabase> = Currentdb


Or
Set <VariableDatabase> = DAO.Opendatabase("path\file")
> Currentdb *Y Database 
> DAO.Opendatabase("Path\File") *Y Database _`f#4K

72

www.enteritc.com

Microsoft Access 2010 Advance




Enter Information Technology Center

Ex:

Set db = Currentdb
Set db = DAO.Opendatabase("C:\Enter.accdb")
3.  TableDef Object:
TableDef Object 2 DAO &'k* Table f# Database

Ex: 92&'w/ Table *f# Database

Access 2010 Advance

www.enteritc.com

73




Enter Information Technology Center

Ex: 92&'w/ Fileds *f# TableProduct

4.  QueryDef Object:


QueryDef Object 2 DAO &'k* Query *
f# Database

74

www.enteritc.com

Microsoft Access 2010 Advance




Enter Information Technology Center

Ex: 92&'w/ Query *f# Database

Access 2010 Advance

www.enteritc.com

75




Enter Information Technology Center


5.  RecordSet Object:

RecordSet Object 2 DAO # # Table Query 


K
| }#f# Memory |f Form
Syntax:

Dim <VariableRecordset> As DAO.Recordset


Ex:

Dim rs As DAO.Recordset

M VariableRecordset MX Syntax 9 :


Syntax:

Set <VariableRecordset> = <VariableRecordset>.OpenRecordset


("<TableName>|<SQL>")

> TableName *Y 2w/ Table VariableRecordset  Sore 


> SQL 2 SQL Statement # Table
Ex:

Set rs = db.OpenRecordset("TableProduct")
6.  Add Record  Do While # & Recordset:

76

www.enteritc.com

Microsoft Access 2010 Advance




Enter Information Technology Center

7.  Edit Record # & Recordset:

Access 2010 Advance

www.enteritc.com

77




Enter Information Technology Center

8.  Find Record # & Recordset:

78

www.enteritc.com

Microsoft Access 2010 Advance




Enter Information Technology Center

9.  Delete Record # & Recordset:

Access 2010 Advance

www.enteritc.com

79




Enter Information Technology Center

10. ( Button Clear:

80

www.enteritc.com

Microsoft Access 2010 Advance




Enter Information Technology Center

11. ( Button Delete All:

Access 2010 Advance

www.enteritc.com

81




Enter Information Technology Center


12. ( Navigation Record # & Recordset:

82

www.enteritc.com

Microsoft Access 2010 Advance




Access 2010 Advance

Enter Information Technology Center

www.enteritc.com

83




Enter Information Technology Center


13. ):

84

www.enteritc.com

Microsoft Access 2010 Advance




Enter Information Technology Center

 6:  ComboBox &

Listbox  DAO
1. !"!# ComboBox & ListBox:
ComboBox ListBox  Control  Application 
!" Microsoft Access '(*

,
 ./01
34 5 07, TextBox 8 '.: >
@ E ComboBox FG Item JK ListBox FG Items N.
P3 Add Items Q ComboBox ListBox S U S Wizard N
Table, Add Items 07,S Form N00 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
0FG
> Value List: * ComboBox 3JK 0' N
(Unbound)  Table/Query 8
3. & RowSource Property:
8, RowSourceType Property  

N0  ComboBox ListBox
* 8 RowSource Property E (4
SNFG RowSourceTyp RowSource Property 
ListBox:
1. FormProduct Switch Q Design View >
2. ListBox ! Form 00"h ListBoxTableProduct Label '1 >

Access 2010 Advance

www.enteritc.com

85




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,  >

86

www.enteritc.com

Microsoft Access 2010 Advance




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

Access 2010 Advance

www.enteritc.com

87




Enter Information Technology Center

Ex:

5. & Column Heads Property:


Column Heads Property (FG" Field N! ComboBox ListBox
  Bound
Ex:

88

www.enteritc.com

Microsoft Access 2010 Advance




Enter Information Technology Center

6. & Column Widths Property:


Column Widths Property ( Field (! ComboBox ListBox
  Bound 0P ' in cm 
Ex:

Access 2010 Advance

www.enteritc.com

89




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

90

www.enteritc.com

Microsoft Access 2010 Advance




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

Access 2010 Advance

www.enteritc.com

91




Enter Information Technology Center

> ! On Load Form  On Click Event ButtonAddKhan


:

4.  PageSangkat Property  >

92

> Label of CoboBox

: Caption = ProvinceName

> ComboBox

: Name = ComboBoxProvinceNameInKhan

> Label of TextBox

: Caption = KhanName

> TextBox

: Name = TextKhanName

> Button

: Name = ButtonAddKhan ; Caption = AddKhan

www.enteritc.com

Microsoft Access 2010 Advance




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

Access 2010 Advance

www.enteritc.com

93




Enter Information Technology Center

> Label of ListBox2

: Caption = SangkatName

> ListBox2

: Name = ListBoxSangkatNameAllInfo

> ! On Load Form :

> ! AfterUpdate ComboBoxProvinceNameAllInfo :

> ! AfterUpdate ListBoxKhanNameAllInfo :

94

www.enteritc.com

Microsoft Access 2010 Advance




Enter Information Technology Center

6. 

Access 2010 Advance

www.enteritc.com

95




Enter Information Technology Center

96

www.enteritc.com

Microsoft Access 2010 Advance




Enter Information Technology Center

 7: 

Keyword Execute  DAO


1. :
Execute  Keyword 
  DAO 
! $ action query
% 
! Query Run )
Syntax:

Vardatabase.Execute sqlstatements

> vardatabase : Variable , DAO.database


> sqlstatements : SQL Statement 0
!  )%
Ex:
1. 3 Form , Property 5 >

2.  ButtonAdd 5:

Access 2010 Advance

www.enteritc.com

97




Enter Information Technology Center


2. % Excute:

795)@ Execute 3 Form Student Change Class

J7N5:
1. 3 TableStudents ,5 >

2. U W $ Table 5 >

98

www.enteritc.com

Microsoft Access 2010 Advance




Enter Information Technology Center

3. 3 Form ,,5 >

4.  Form_Load 5 >

Private Sub Form_Load()


Me.ComboBoxFromGroup.RowSource
from TableStudents"
Me.ComboBoxToGroup.RowSource =
from TableStudents"
Me.ComboBoxFromClass.RowSource
from TableStudents"
Me.ComboBoxToClass.RowSource =
from TableStudents"

= "Select Distinct Group


"Select Distinct Group
= "Select Distinct Class
"Select Distinct Class

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

Access 2010 Advance

www.enteritc.com

99




Enter Information Technology Center

5.  ComboBoxFromGroup_AfterUpdate 5 >

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

6.  ComboBoxFromClass_AfterUpdate 5 >

Private Sub ComboBoxFromClass_AfterUpdate()


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

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

100

www.enteritc.com

Microsoft Access 2010 Advance




Enter Information Technology Center

8.  ComboBoxToClass_AfterUpdate 5 >

Private Sub ComboBoxToClass_AfterUpdate()


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

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

Access 2010 Advance

www.enteritc.com

101




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

102

www.enteritc.com

Microsoft Access 2010 Advance




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 >

Access 2010 Advance

www.enteritc.com

103




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
104

www.enteritc.com

Microsoft Access 2010 Advance




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

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

Access 2010 Advance

www.enteritc.com

105




Enter Information Technology Center

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

4.  FormExport:
1.  FormExport  Property =2 >

2. * ButtonSubtract_Click =2 >

106

www.enteritc.com

Microsoft Access 2010 Advance




Enter Information Technology Center

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

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

Access 2010 Advance

www.enteritc.com

107




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

5. $:
1.  FormStock =2:

108

www.enteritc.com

Microsoft Access 2010 Advance




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"
Access 2010 Advance

www.enteritc.com

109




Enter Information Technology Center

Set rs3 = db.OpenRecordset("TableExport")


Me.ListBoxExport.ColumnHeads = True
Me.ListBoxExport.ColumnCount = 4
Me.ListBoxExport.RowSource = "Select * from
TableExport"
End Sub

3.  ButtonSearchImport_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
4.  ButtonSearchExport_Click  >

110

www.enteritc.com

Microsoft Access 2010 Advance




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

Access 2010 Advance

www.enteritc.com

111

You might also like