SETEC University Management Information System
Table of Contents I
Table of Contents
Chapter 1 .............................................................................................................................................1
Introduction to MS-Access 2007.........................................................................................................1
1.1. របបៀបបបើកកម្មវិធី MS-Access 2007: ...................................................................................1
1.2. របបៀបបិទកម្មវិធី MS-Access 2007 ......................................................................................3
1.3. របបៀបបប្កើត Database ថ្មី .....................................................................................................3
1.4. របបៀបបបើក Database ដែលមានស្រាប់................................................................................5
Chapter 2 .............................................................................................................................................6
Creating and Using Table....................................................................................................................6
2.1. របបៀបបប្កើត Table ថ្មីែំបូ្..................................................................................................6
2.2. របបៀបបប្កើត Table ថ្មីបដនែម្................................................................................................7
2.3. របបៀបបប្កើត Table ថ្មីបដនែម្ បោយប្បើ Table Templates...................................................7
2.4. របបៀបបដនែម្ Field/Column ចូលកនុ្ Table.........................................................................7
2.5. របបៀបបដនែម្ Field/Column ចូលកនុ្ Table បោយប្បើ Field Templates ............................7
2.6. របបៀបបដនែម្ Field/Column ពី Table បផេ្បទៀតកនុ្ Datasheet View:...............................8
2.7. របបៀបលប់ Field/Column បចញពី Table កនុ្ Datasheet View............................................8
2.8. របបៀបបប្កើត Table កនុ្ Design View..................................................................................9
2.9. Primary Key: ......................................................................................................................14
2.10. Import Table:......................................................................................................................14
2.11. Export Tables .....................................................................................................................21
2.12. ភ្ជ
ា ប់បៅកាន់ Table (Link Table): ......................................................................................22
2.13. បប្កើត Lookup Wizard .......................................................................................................24
2.14. Relationships:.....................................................................................................................30
2.15. ការកំនត់ោក់ Password:....................................................................................................33
Chapter 3 ...........................................................................................................................................36
Creating and Using Query.................................................................................................................36
3.1. បប្កើត Select Query បោយប្បើ wizard:.............................................................................37
3.2. របបៀប Run query: ..............................................................................................................39
3.3. បប្កើត Select Query កនុ្ Design View:. ............................................................................40
3.4. ការ Backup Database ទុក:.................................................................................................50
3.5. បប្កើត Delete Query:..........................................................................................................51
3.6. បប្កើត Update Query:.........................................................................................................53
3.7. បប្កើត Append Query:........................................................................................................55
3.8. បប្កើត Make-table Query:..................................................................................................57
3.9. បប្កើត Parameter Query:....................................................................................................60
3.10. បប្កើត Crosstab Query: ......................................................................................................62
3.11. Structure Query Language (SQL): .....................................................................................67
Management Information System SETEC University
II Table of Contents
Chapter 4........................................................................................................................................... 71
Creating and Using Form.................................................................................................................. 71
4.1. បប្កើត Form បោយប្បើ Form tool:.................................................................................... 71
4.2. របបៀប View form:.............................................................................................................. 72
4.3. បប្កើត Form បោយប្បើ Split Form tool ............................................................................ 74
4.4. បប្កើត Form បោយប្បើ Multiple Items tool:..................................................................... 76
4.5. បប្កើត Form បោយប្បើ Wizard......................................................................................... 77
4.6. បប្កើត form បោយប្បើ Blank Form tool: .......................................................................... 79
4.7. ការរំកិល control បលើ form: ............................................................................................... 81
4.8. ការប្បើ្ាស់ form : .......................................................................................................... 82
4.9. បប្កើត Main form និ្ Subform......................................................................................... 83
4.10. Visual Basic for Application(VBA):.................................................................................. 89
4.11. Introduction to Variables: .................................................................................................. 92
4.12. Data Type:.......................................................................................................................... 93
4.13. Introduction to Procedures:.............................................................................................. 100
4.14. Conditional Statements .................................................................................................... 106
4.15. Counting and Looping Structures: ................................................................................... 107
4.16. Data Access Objects(DAO) ............................................................................................. 109
Chapter 5......................................................................................................................................... 114
Creating and Using Report.............................................................................................................. 114
5.1. បប្កើត Report បោយប្បើ Report tool: ............................................................................. 114
5.2. របបៀប View Report.......................................................................................................... 114
5.3. បប្កើត Report បោយប្បើ Report Wizard......................................................................... 117
5.4. បប្កើត Label បោយប្បើ Label Wizard ............................................................................ 121
5.5. បប្កើត Report បោយប្បើ Blank Report tool:................................................................... 124
5.6. អំពី Report Sections: ........................................................................................................ 125
5.7. បប្កើត Grouped Report ថ្មី បោយប្បើ Report Wizard:..................................................... 126
5.8. Homeworks ...................................................................................................................... 132
SETEC University Management Information System
Chapter 1: Introduction to MS-Access 2007 Page 1 of 140
Chapter 1
Introduction to MS-Access 2007
Introduction
Microsoft Access 2007 Computer Application
desktop computer computer network ។
។
MS-Access 2007 ៖
- Table: (Store)
- Query: Tables
- Form: Table
- Report: ជាដ ើម
1.1. MS-Access 2007:
- ១ : Start  (All) Program  Microsoft Office  Microsoft Office
Access 2007 ។
- ២ : Directory : C:Program FilesMicrosoft OfficeOffice12 
File msaccess.exe Double Click ។
- ៣ : Start Run  Open: msaccess Enter
OK ។
Management Information System SETEC University
Page 2 of 140 Chapter 1: Introduction to MS-Access 2007
MS-Access 2007
- Title bar: Office
Button Quick Access Toolbar ។
- Office Button: Button (Save)
Database ។
- Quick Access Toolbar: Icons
Save, Undo Redo ។ Quick Access
Toolbar Customized Button Icons
។
Office Button
Quick Access Toolbar
Customized Button
Title bar
SETEC University Management Information System
Chapter 1: Introduction to MS-Access 2007 Page 3 of 140
- The Work Area: MS-Access 2007
:
១ : Template Categories: (Categori s (Template)
។
២ : :
- (New Blank Database) Database ។
- (Featured Online Templates):
(Template) Database Microsoft ។
៣ : Databases ។
1.2. MS-Access 2007
- Office Button  Exit Access
: Close Button Title bar
: Alt + F4
1.3. Datab s
- Office Button  New
: ១ (Template Categories)
Featuring  Blank Database
- File Name: Database
 Folder
- Save as type Microsoft Access 2007 Database(*.accdb) 
Create ។
Management Information System SETEC University
Page 4 of 140 Chapter 1: Introduction to MS-Access 2007
Program Window MS-Access 2007
- The Ribbon: Program Window Commands
។
- Navigation Pane: objects
Database ។
- Tabbed Documents: Tables, Queries, Forms, Reports Macro
Tab ។
View Button
Ribbon
Navigation Pane Tabbed Documents
Status bar
SETEC University Management Information System
Chapter 1: Introduction to MS-Access 2007 Page 5 of 140
- Status bar: Program Window
Buttons View ។
1.4. Databas
- Office Button  Open
: ៣ (Open recent document):
- Browse Database  Double-Click Database
Open ។
***End of Chaptert 1***
Management Information System SETEC University
Page 6 of 140 Chapter 2: Creating and Using Table
Chapter 2
Creating and Using Table
អ្វីដៅជា Table?
Table object MS-Access
។
2.1. T l
1. Database
2. Program Window :
3. Tabbed document, double-click Field/Column Headers
: Right-click Field/Column Headers  Rename column
4. Column  Tab
Field … Enter
5. Save Table  OK
Field/Column Headers
Row/Record
Headers
Tabbed document
SETEC University Management Information System
Chapter 2: Creating and Using Table Page 7 of 140
2.2. T l
1. Ribbon, Create  Icon: Table
2. Tabbed document, double-click Field/Column Headers
: Right-click Field/Column Headers  Rename column
3. Column  Tab
Field … Enter
4. Save Table  OK
2.3. T l Table Templates
1. Ribbon, Create  Icon: Table Templates
Templates
2. Save Table  OK
2.4. Fi l olumn Table
១ :
1. Table Datasheet View
2. Right-click Field/Column Header Column
3. Insert Column
២ :
1. Field/Column Header Column
2. Ribbon, Datasheet  Fields & Column, Icon: Insert
2.5. Fi l olumn T l Field
Templates
1. Table Datasheet View
2. Field/Column Header
Column
Management Information System SETEC University
Page 8 of 140 Chapter 2: Creating and Using Table
3. Ribbon, Datasheet  Fields & Column, Icon: New Field
4. Field Templates, Fields
Table ។
2.6. Fi l olumn T l Datasheet View:
1. Table Datasheet View
2. Field/Column Header
Column
3. Ribbon, Datasheet  Fields & Column,
Icon: Add Existing Field
4. Field List, Fields
Table
2.7. Fi l olumn T l Datasheet View
១ :
1. Table Datasheet View
2. Right-click Field/Column Header Field
3. Delete Column  YES
២ :
1. Table Datasheet View
2. Field/Column Header Field
3. Ribbon, Datasheet  Fields & Column, Icon: Delete 
YES
SETEC University Management Information System
Chapter 2: Creating and Using Table Page 9 of 140
2.8. T l Design View
1. Ribbon, Create  Icon: Table Design
2. Field Name: Field Table
3. Data Type: user Field :
- Text: ២៥៥
- Memo: ៦៣ ។
support Rich Text Formatting ។
E.g: Property: Text Format = Rich Text)
- Number:
- Date/Time: ១
- Currency:
Management Information System SETEC University
Page 10 of 140 Chapter 2: Creating and Using Table
- AutoNumber: user
record
- Yes/No: user (Yes/No,
True/False, or On/Off)
- OLE Object: Object (Files) word, excel, graphics,
sound
- Hyperlink: Text (Path/URL) File,
Web Page Website
- Attachment: (attach) images, word, excel
records Database
- Lookup Wizard: Field user
List Table List box Combo box
4. Description: Field Status bar
5. Field Properties: Fields
SETEC University Management Information System
Chapter 2: Creating and Using Table Page 11 of 140
Field Properties Data Type
Data Type Field Properties
Text - Field Size: user Field
- Format: Datasheet View
>:
<:
@[color]:
E.g :
@[red]/[black]/[blue]/[green]/[cyan]/[magenta]/[yellow]/[white]
- Input Mask: :
0 (zero): + -
9 (nine):
+ - ។
# : +
- ។ : Space user ។
L: A
? (Question mark): A
A:
a:
&: sp
C: sp
<:
>:
- Caption: Label Column Heading Datasheet view Form
- Validation Rule: Field
- Validation Text: Text Message box
user Validation Rule
Management Information System SETEC University
Page 12 of 140 Chapter 2: Creating and Using Table
Data Type Field Properties
- Required: - o Field
- Yes: Field
- Allow Zero Length:
- No: String Null string
- Yes: String Null string
- Indexed:
- No: The field is not indexed (default). index Field
- Yes(Duplicates OK): index Field user
- Yes(No Duplicates): index Field user
Number - Field Size:
- Byte: 1 byte of memory or disk space, holds from 0 to 255
- Integer: 2 bytes of storage, holds from -32,768 to 32,767
- Long Integer: 4 bytes of storage, holds from -2,147,483,648 to
2,147,483,647
- Single: 4 bytes of storage, holds from -3.402823x1038
to
3.402823x1038
- Double: 8 bytes of storage, holds from -1.79769313486232x10308
to
1.79769313486232x10308
- Format:
- 000: to put 00 left number E.g.: 001
- #,##0.00R: format Riel E.g.: 10,000.00R
Date/Time - Format:
- d: Display the day of the month as one or two digits.
- dd: Display the day of the month using two digits.
SETEC University Management Information System
Chapter 2: Creating and Using Table Page 13 of 140
Data Type Field Properties
- ddd: Display the first three letters of the day of the week.
- dddd: Display the full name of the day of the week.
- m: Display the month of the year as one or two digits.
- mm: Display the month of the year using two digits.
- mmm: Use the first three characters of the month.
- mmmm: Use the full name of the month.
- yy: Use the last two digits of the year.
- yyyy: Use the full year.
- h: Display the hour using one or two digits.
- hh: Display the hour using two digits.
- n: Display the minute using one or two digits.
- nn: Display the minute using two digits.
- s: Display the second using one or two digits.
- ss: Display the second using two digits.
- Input Mask:
- Date: 00/00/00
- Time: 00:00:00
E.g. 1 :
Input mask Sample values
(000) 000-0000 (206) 555-0248
(999) 999-9999 (206) 555-0248
( ) 555-0248
(000) AAA-AAAA (206) 555-TELE
#999 -20
2000
>L????L?000L0 GREENGR339M3, MAY R 452B7
Management Information System SETEC University
Page 14 of 140 Chapter 2: Creating and Using Table
>L0L 0L0 T2F 8M4
00000-9999 98115-
98115-3007
>L<?????????????? Maria
Brendan
SSN 000-00-0000 SSN 555-55-5555
>LL00000-0000 DB51392-0493
E.g. 2:
ValidationRule Property ValidationText Property
<> 0 Entry must be a nonzero value.
> 1000 Or Is Null Entry must be blank or greater than 1000.
Lik “A????" Entry must be 5 characters and begin with the letter "A".
2.9. Primary Key:
Primary Key Field (Records)
Table ។
 Field Primary Key:
1. Table Design View  Field Primary
Key
2. Ribbon, Tab: Design  Icon: Primary Key
 Primary Key Field:
1. Table Design View  Field Primary Key
2. Ribbon, Tab: Design  Icon: Primary Key
2.10.Import Table:
 Import Table Database
1. Database Import Table
SETEC University Management Information System
Chapter 2: Creating and Using Table Page 15 of 140
2. Ribbon, t “Ext rn l D t ”  Import: Access
Window :
3. Browse Database Tables
4. “Import T l s, qu ri s, forms, …”  OK
Window :
Management Information System SETEC University
Page 16 of 140 Chapter 2: Creating and Using Table
5. “Import O j t”, tab: Tables  Tables
Import  OK
6. “S v import st ps”  Close
 Import Table File MS-Excel
1. Database Import Table
2. Ribbon, t “Ext rn l D t ”  Import:
Excel Window :
SETEC University Management Information System
Chapter 2: Creating and Using Table Page 17 of 140
Browse File MS-Excel Tables
3. “Import th sour t …”  OK
Window “Import Spr sh t Wiz r ” :
Management Information System SETEC University
Page 18 of 140 Chapter 2: Creating and Using Table
4. “Show Worksh ts” List sheet
Import  Next window :
SETEC University Management Information System
Chapter 2: Creating and Using Table Page 19 of 140
5. “First Row ont ins olumn H ing” row ១
Column heading  Next window :
6. Field :
 Field Name: Field
 Data Type:
 Indexed: Index
 “Do not import fi l Skip ” Import
Field
7. Next window :
Management Information System SETEC University
Page 20 of 140 Chapter 2: Creating and Using Table
8. :
 Let Access add primary key: Access primary key
 Choose my own primary key: Field primary key
 No primary key: primary key
9. Next window :
SETEC University Management Information System
Chapter 2: Creating and Using Table Page 21 of 140
10. Table Import “Import to T l ”  Finish
11. Close
2.11. Export Tables
 Export table File MS-Excel:
1. Navigation bar, table
Export
2. Ribbon, t “Ext rn l D t ”  Export:
Excel Window :
Management Information System SETEC University
Page 22 of 140 Chapter 2: Creating and Using Table
3. Browse Export table 
options :
 Export data with formatting and layout: Export
format layout
 Open the destination file after the export operation is complete: file
export export
 Export only the selected records: Export records
4. OK  Close
2.12. Table (Link Table):
 Link Table Database :
1. Database Link table
2. Ribbon, tab: External Data 
Import, Icon: Access Window :
SETEC University Management Information System
Chapter 2: Creating and Using Table Page 23 of 140
3. Browse Database Link tables
4. “Link to th t sour …”  OK
Window :
5. “Link T l s”, Tables Link 
OK
Management Information System SETEC University
Page 24 of 140 Chapter 2: Creating and Using Table
2.13. Lookup Wizard
 Lookup Wizard :
1. table Design View
2. Data type: Lookup Wizard Field Lookup
Wizard (E.g.: Sex)
3. win ow “Lookup Wiz r ” :
SETEC University Management Information System
Chapter 2: Creating and Using Table Page 25 of 140
4. “I will typ in th v lu s th t I w nt”  Next
window :
 Number of columns: columns
5. Col1, Lookup column (E.g.:
6. Next window :
7. lookup column  Finish
8. Save table
Management Information System SETEC University
Page 26 of 140 Chapter 2: Creating and Using Table
 Lookup Wizard Tables/Queries :
1. table Design View
2. Data type: Lookup Wizard Field Lookup
Wizard win ow “Lookup Wiz r ” :
3. “I w nt th lookup olumn to look up th v lu s in t l or
qu ry”  Next
SETEC University Management Information System
Chapter 2: Creating and Using Table Page 27 of 140
4. table query Lookup
column  Next
5. Fields “Av il l Fi l s” Field
Lookup column  Next
6. sort order (Ascending/Descending) Fields 
Next
Management Information System SETEC University
Page 28 of 140 Chapter 2: Creating and Using Table
7. column mouse (drag) column
 “Hi k y olumn r omm n ”
key column
8. Next
9. lookup column  Finish
10. + Yes: save table relationships
+ No: relationships
SETEC University Management Information System
Chapter 2: Creating and Using Table Page 29 of 140
11.Save table
 lookup column Field
1. table Design View  Field lookup column
2. Field Properties, tab: Lookup  “Displ y
ontrol”, Text Box
3. Save table
Management Information System SETEC University
Page 30 of 140 Chapter 2: Creating and Using Table
2.14. Relationships:
 Relationships:
1. Ribbon, tab: Database Tools 
Show/Hide, Icon: Relationships
Relation tab :
2. tab: Design Icon: Show Tables
: Right-click Relationship Window  Show Tables
“Show T l ” :
SETEC University Management Information System
Chapter 2: Creating and Using Table Page 31 of 140
3. tab: Tables  tables relationship 
Add
4. Close
5. Primary key (drag) Foreign key Edit
Relationships :
Management Information System SETEC University
Page 32 of 140 Chapter 2: Creating and Using Table
6. Create
7. tab: Design Icon: Close Relationship tab
 Relationship:
1. tab: Design Icon: Relationship
2. Double-click Relationship tie
: Right-click Relationship tie  “E it R l tionship…”
Relationship tie
SETEC University Management Information System
Chapter 2: Creating and Using Table Page 33 of 140
3. Relationship :
 Enforce Referential Integrity:
Relationship Tables
។
 Cascade Update Related Fields: rim ry y
Foreign Key ។
 Cascade Delete Related Records:
Primary table Foreign table
។
4. OK
 Relationship:
1. tab: Design Icon: Relationship
2. Relationship tie  key: Delete
: Right-click Relationship tie  Delete
3. Yes
2.15. Password:
 Password Database:
1. database Exclusive Mode:
Management Information System SETEC University
Page 34 of 140 Chapter 2: Creating and Using Table
- Office Button  Open
- Database
Password  button:
Open  “Op n
Ex lusiv ”
SETEC University Management Information System
Chapter 2: Creating and Using Table Page 35 of 140
2. Ribbon, tab: Database Tools  Database Tools, Icon:
Encrypt with Password
3. Password:
 Password: Password
 Verify: Password
4. OK
 Password Database
1. database Exclusive Mode
2. Ribbon, tab: Database Tools 
Database Tools, Icon: Decrypt Database
3. Password  OK
Management Information System SETEC University
Page 36 of 140 Chapter 3: Creating and Using Query
Chapter 3
Creating and Using Query
I. Query?:
Query object MS-Access
table tables ។ Query
។ Query
Form, Report Data
Access Page ។
Query MS-Access :
1. Select Query: u ry
table
។ Select Query
: Sum, Count, Average, Max in ។
2. Action Query: Query
t l s ។ Action Query
៤ :
- Delete Query : table
- Update Query : table
។
- Append Query : table table
។
- Make-table Query: table t l
។
3. Parameter Query: Query
។
4. Crosstab Query: Query
។ sum, average,
SETEC University Management Information System
Chapter 3: Creating and Using Query Page 37 of 140
ount,…
។
5. Structured Query Language (SQL): query
SQL Statement SQL Commands (SELECT,
UPDATE DELETE) , SQL Clauses (WHERE ORDER ។
SQL relational databases
Microsoft Access ។
II. Query:
3.1. S l t u ry wizard:
1. Ribbon, tab: Create  Other, Icon: Query
Wizard Win ow “ w u ry” :
2. “Simpl u ry Wiz r ”  OK
Management Information System SETEC University
Page 38 of 140 Chapter 3: Creating and Using Query
3. “T l s u ri s”, Table 
List “Av il l Fi l s”, Fields Query
List “S l t Fi l s”
4. Next
5. “D t il shows v ry fi l of v ry r or ”  Next
SETEC University Management Information System
Chapter 3: Creating and Using Query Page 39 of 140
6. query  “Op n th qu ry to vi w inform tion” 
Finish
Lab 1: Create select query by using wizard:
1. t s “ orthwin . ”
2. Select Query table Products : ProductID, ProductName,
UnitPrice, UnitsInStock.
3. Save query “qry ro u ts”
Lab 2: Create select query by using wizard: (Modify the query design)
1. t s “ orthwin . ”
2. Select Query table Customers : CustomerID, ContactName,
Address, City, Phone
3. S v th qu ry s “qry ustom r ont t” n hoos “ o ify th qu ry sign”
3.2. Run query:
1. Ribbon, Query Tools: Design  Result, Icon: Run
Management Information System SETEC University
Page 40 of 140 Chapter 3: Creating and Using Query
3.3. S l t u ry Design View:.
1. Ribbon, tab: Create  Other, Icon: Query
Design Win ow “Show T l ” :
2. tab: Tables  Tables 
Add  Close Query Window :
3. Double-click Field
: mouse Field (drag)
- Fi l table
- T l tables
SETEC University Management Information System
Chapter 3: Creating and Using Query Page 41 of 140
- Sort (Ascending/Descending).
- Show
- Criteria: ។
: >,
<, <=, >=, Is Null, Is Not Null, Between…An …, In, ot In, Lik , An , Or,<>,… ។
** Like: (wildcards) :
១ E.g. Lik “sm ”
? E.g. Lik “sm?th”
h r t r E.g. Lik “sm iy th”
E.g. Lik “sm i th”
-
E.g. Lik “ - ”
* Disable the output of all fields in query design:
- Office Button  Access Options Object Designer  “ u ry D sign”,
uncheck  Output all fields
Management Information System SETEC University
Page 42 of 140 Chapter 3: Creating and Using Query
Lab: Select Query Design View:
1. database: Northwind.accdb
2. Select Query table: Customers :
a. (Sort: Ascen ing
CompanyName ។
b. London
c. Fr ។
3. Select query table Products :
a. ៥ ។
b. ៣
t goryID=8 S foo ។
c. Chang Unit ri
$18.00 ។
4. Select query table Orders :
a. 12/11/1996
20/04/1997 ShipCountry=Germany ។
b. (ShipRegion) WA, CA, SP ។
c. (ShipRegion) ។
5. Select query t l ustom rs Orders
។
Homework
1. ProductName, UnitPrice CategoryName
(Categories) Seafood ។
2. ProductName, UnitPrice CategoryName
១ (Categories) Seafood ។
3. CategoryID, ProductName, UnitPrice UnitsInStock
“r” ៣ E.g: Norwood, Carnarvon,
Sir Ro n y, … ។
SETEC University Management Information System
Chapter 3: Creating and Using Query Page 43 of 140
E.g:
> 234 Returns all numbers greater than 234. To find all numbers less
than 234, use < 234.
>= "Cajhen" Returns all records from Cajhen through the end of the alphabet
Between #2/2/2007#
And #12/1/2007#
Returns dates from 2-Feb-2007 through 1-Dec-2007 (ANSI-89). If
your database uses the ANSI-92 wildcard characters, use single
quotation marks (') instead of pound signs (#). Example: Between
'2/2/2007' And '12/1/2007'
Not "Germany" Finds all records where the exact contents of the field are not
exactly equal to "Germany." The criterion will return records that
contain characters in addition to "Germany," such as "Germany
(euro)" or "Europe (Germany)".
Not "T*" Finds all records except those beginning with T. If your database
uses the ANSI-92 wildcard character set, use the percent sign (%)
instead of the asterisk (*).
Not "*t" Finds all records that do not end with t. If your database uses the
ANSI-92 wildcard character set, use the percent sign (%) instead
of the asterisk (*).
In(Canada,UK) In a list, finds all records containing Canada or UK.
Like "[A-D]*" In a Text field, finds all records that start with the letters A through
D. If your database uses the ANSI-92 wildcard character set, use
the percent sign (%) instead of the asterisk (*).
Like "*ar*" Finds all records that include the letter sequence "ar". If your
database uses the ANSI-92 wildcard character set, use the
percent sign (%) instead of the asterisk (*).
Management Information System SETEC University
Page 44 of 140 Chapter 3: Creating and Using Query
Lik “ ison
Dewe?"
Finds all records that begin with "Maison" and contain a 5-letter
second string in which the first 4 letters are "Dewe" and the last
letter is unknown. If your database uses the ANSI-92 wildcard
character set, use the underscore (_) instead of the question mark
(?).
#2/2/2007# Finds all records for February 2, 2007. If your database uses the
ANSI-92 wildcard character set, surround the date with single
quotation marks instead of pound signs ('2/2/2007').
< Date() - 30 Uses the Date function to return all dates more than 30 days old.
Date() Uses the Date function to return all records containing today's
date.
Between Date() And
D t A “ ", 3,
Date())
Uses the Date and the DateAdd functions to return all records
between today's date and three months from today's date.
Is Null Returns all records that contain a null (blank or undefined) value.
Is Not Null Returns all records that contain any value (that are not null).
“" Returns all records that contain a zero-length string. You use zero-
length strings when you need to add a value to a required field, but
you don't yet know what the actual value is. For example, a field
might require a fax number, but some of your customers might not
have fax machines. In that case, instead of entering a number, you
enter a pair of double quotation marks with no space between them
“" .
3.3.1. Alias field name: Field query
: NewFieldName : OldFieldName
E.g 1. : Name : FirstName
SETEC University Management Information System
Chapter 3: Creating and Using Query Page 45 of 140
E.g 2. Full m First m & “ “ & L st m
E.g 3. : Sub Total : [UnitPrice]*[Quantity]
3.3.2. Aggregate function:
1. Select Query Design View
2. Ribbon, Query Tools: Design
3. Show/Hide, Icon: Total Total grid
:
4. Total grid, Aggregate function fields :
Group y, Sum, ount, Avg, x, in, …
Total grid
Management Information System SETEC University
Page 46 of 140 Chapter 3: Creating and Using Query
5. Run
3.3.3. Expression Builder:
1. Select Query Design View
2. Field
3. Ribbon, Query Tools: Design  Query Setup, Icon: Builder
: Right-click Field  Builder
SETEC University Management Information System
Chapter 3: Creating and Using Query Page 47 of 140
4. Double-Click folder: Function  Built-In Function 
functions Double-click function
5.  OK
6. Run query
Lab1: Select Query Aggregate function
1. database Northwind.accdb
2. Select Query table Products
a. Group by CategoryID
b. Sum on UnitsInStock
3. Save query “qryUnitsInSto k y t gory”
4. Run the query
Lab2: Calculation using Expression Builder
1. database Northwind.accdb
2. Select Query table OrderDetails fields: OrderID,
ProductID, UnitPrice, Quantity
3. field :
- SubTotal Before Discount: [UnitPrice]*[Quantity]
- Discount Price: [UnitPrice]*[Quantity]*Discount
function function
Management Information System SETEC University
Page 48 of 140 Chapter 3: Creating and Using Query
- SubTotal After Discount: [SubTotal Before Discount] – [Discount Price]
: SubTotal After Discount: [UnitPrice]*[Quantity]*(1-[Discount])
: SubTotal After Discount$: Format([UnitPrice]*[Quantity]*(1- Dis ount ,” urr n y”
4. S v qu ry s “qrySu Tot l”
3.3.4. Build-in Function - IIF: Function
។
: IIf(expression, truepart, falsepart)
expression:
truepart:
falsepart:
E.g.1 R sult IIf S or >=50,” ss ”,”F il ”
E.g.2 : Mention: IIf([TotalScore] Between 450 And 500,"Excellent",IIf([TotalScore]
Between 350 And 449,"Very Good",IIf([TotalScore] Between 200 And
349,"Good","Poor")))
E.g. 3 L ngu g IIf ountryR gion =“It ly”, “It li n", “Som oth r l ngu g "
E.g. 4: Status: IIf([Due Date]<Date(),“OVERDUE",IIf([Due Date]=Date(),“Due",“Not Yet Due"))
Lab 1: Build-in function IIF
1. database Northwind.accdb
2. Select Query table Products : ProductID, ProductName,
UnitInStock
3. field StockStatus
UnitsInStock=0 “ ro u t out of sto k”
“ ro u t not out of sto k”
4. Save query “qrySto kSt tus”
SETEC University Management Information System
Chapter 3: Creating and Using Query Page 49 of 140
Lab: nested function IIF
1. database Northwind.accdb
2. Select Query table Products : ProductID, ProductName,
UnitsInStock, UnitPrice
3. field Mention
UnitPrice 1 - 20 ntion “V ry h p”
UnitPrice 21 - 50 ntion “ h p”
UnitPrice 51 - 70 ntion “Exp nsiv ”
UnitPrice > 70 ntion “V ry Exp nsiv ”
4. Save query “qry ro u t ntion”
3.3.5. Build-In-Function :
Abs(Number): Absolute value
Avg(expr): Average
CBool(expr): Convert to Boolean
CByte(expr): Convert to byte
CCur(expr): Convert to currency
CDate(date): Convert to date
CDbl(expr): Convert to double
CInt(expr): Convert to integer
CLng(expr): Convert to long integer
Chr(charcode): Convert ascii to character
Asc(Strexpr): Convert character to ascii
Date(): Display current date
DateAdd(Interval,Number,Date): Add to
date by interval
DateDiff(Interval,Date1,Date2): Date2
minus Date1 by interval
DatePart(Interval,Date): Select date by
interval
* Interval : Year yy, yyyy
Quarter q, q
Month mm, m
Management Information System SETEC University
Page 50 of 140 Chapter 3: Creating and Using Query
* Interval : Day dd, d
Week wk, ww
Hour hh
Minute mi, n
Second ss, s
Milisecond ms
Ex D t rt “yyyy”,D t
* Build-in functions - Date/Time
- DateAdd(Interval,Number,Date):
interval
E.g. : D t A “yyyy”,10, Hir D t
- DateDiff(Interval,Date1,Date2): Date2 Date1
interval
E.g. : D t Diff “yyyy”, irthD t , ow
- DatePart(Interval,Date):
interval
E.g. : D t rt “ ”, irthD t
D t rt “m”, irthD t
D t rt “yyyy”, irthD t
* Build-in functions - Format()
E.g. : Form t irthD t , “yyyy”
Form t Amount , “ urr n y”
Format([Amount], “៛ #,##0.00")
10 Year Aniversary: Format(DateAdd("m",10,[HireDate]),"dd/mmm/yy")
3.4. kup D t s :
1. Database file Back up
2. Office button  Manage  Back Up Database
SETEC University Management Information System
Chapter 3: Creating and Using Query Page 51 of 140
3. Save As dialog box, browse Database file
4. File name, Database file Back up
5. Save
3.5. Delete Query:
table ។
1. S l t u ry Design View
2. Ribbon, Query Tools: Design
3. Query Type, Icon: Delete Delete grid
:
Management Information System SETEC University
Page 52 of 140 Chapter 3: Creating and Using Query
4. field record:
- Field: field
- Table: table
- Delete: + From: field table record
+ Where: field
5. Run the query
Delete grid
SETEC University Management Information System
Chapter 3: Creating and Using Query Page 53 of 140
6. Yes records
L D l t u ry :
1. records table: Order Details (UnitsInStock)
30 ។
2. table: Orders OrderID 10500 ។
3. table: Orders
ID = “ LAUS” ។
4. table: Products (CategoryName)
Seafood ។
3.6. Update Query:
table ។
1. S l t u ry Design View
2. Ribbon, Query Tools: Design
3. Query Type, Icon: Update Update grid
Management Information System SETEC University
Page 54 of 140 Chapter 3: Creating and Using Query
4. fields fields Update record
- Field: field Update record
- Table: table
- Update To:
- Criteria:
5. Run the query
Update grid
SETEC University Management Information System
Chapter 3: Creating and Using Query Page 55 of 140
6. Yes
Lab: Update query
1. Country=“ xi o” “ m o i ” table: Customers
2. Update Unit ri t l ro u ts
១ stock
២ ។
3.7. Append Query:
record table ។
1. S l t u ry Design View Source table
2. Ribbon, Query Tools: Design
3. Query Type, Icon: Append
4. :
- T l m Destination table record
- Current Database: Database
- Anoth r D t s record table database
Management Information System SETEC University
Page 56 of 140 Chapter 3: Creating and Using Query
5. OK  fields fields Append
- Field: Field Source table
- Table: Source table
- Append To: Field Destination table
- Criteria:
6. Run the query
7. Yes
SETEC University Management Information System
Chapter 3: Creating and Using Query Page 57 of 140
L r t App n u ry :
1. table Clients table: Customers
2. table Customers ountry=” xi o”
table Clients ។
3. table Customers fax
table Clients ។
4. table Customers
Germany table Clients ។
5. table Customers Canada UK
table Clients ។
E.g.:
< Date() - 30 Returns all dates more than 30 days old.
Betw n D t An D t A “ ", 3, D t Returns ll r or s tw n to y‘s date
and three months from today‘s date.
3.8. Make-table Query:
table t l
។
1. S l t u ry Design View tables
2. Ribbon, Query Tools: Design
3. Query Type, Icon: Make-table Query :
4. :
- T l m table record
Management Information System SETEC University
Page 58 of 140 Chapter 3: Creating and Using Query
- Current Datab s table Database
- Anoth r D t s table database
5. OK
6. fields fields table
7. Run the query
8. Yes
SETEC University Management Information System
Chapter 3: Creating and Using Query Page 59 of 140
Lab: Make-table query :
1. database Northwind.accdb
2. t l CustomerAG fields: CustomerID, ContactName,
Address ity table: Customers ID
A G ។
3. t l ustom rLon on ri fields: CustomerID,
ContactName, Address ity table: Customers
London Madrid ។
4. t l ro u t otSE fields: ProductID, ProductName,
UnitPrice UnitsInStock table: Products
“s” “ ” ។
Management Information System SETEC University
Page 60 of 140 Chapter 3: Creating and Using Query
3.9. Parameter Query:
Query
។
1. S l t u ry Design View tables
2. fields field Parameter
Query
3. Parameter Query Criteria field
E.g: Between [Start Date] And [End Date]
4. Run the query Parameter
SETEC University Management Information System
Chapter 3: Creating and Using Query Page 61 of 140
Lab: Create Parameter query
1. query table: Orders
(OderDate) (Begin Date End Date) ។
2. query table: Products
stock ។
3. query table: Customers
(CompanyName) ។
4. query table: Customers
omp ny m ។
Management Information System SETEC University
Page 62 of 140 Chapter 3: Creating and Using Query
3.10. Crosstab Query:
Query
។
1. Ribbon, tab: Create  Other, Icon: Query Wizard
Win ow “ w u ry” :
2. “ rosst u ry Wiz r ”  OK
Column Heading
Row Heading
SETEC University Management Information System
Chapter 3: Creating and Using Query Page 63 of 140
3. table query Crosstab Query 
Next
4. field Row Heading  Next
Management Information System SETEC University
Page 64 of 140 Chapter 3: Creating and Using Query
5. field Column Heading  Next
6. interval field Date/Time
SETEC University Management Information System
Chapter 3: Creating and Using Query Page 65 of 140
7. field function field 
Next
8. query  Finish
Management Information System SETEC University
Page 66 of 140 Chapter 3: Creating and Using Query
Lab: Crosstab query:
1. database Northwind.accdb
2. crosstab query table Customers customers
ountry (City) ។
3. crosstab query table Orders
។
4. Wizard, crosstab query table: Orders Shippers
(Freight) (ShipCountry)
(CompanyName) ។
SETEC University Management Information System
Chapter 3: Creating and Using Query Page 67 of 140
3.11. Structure Query Language (SQL):
query SQL Statement
SQL Commands (SELECT, UPDATE DELETE), SQL CLAUSES (WHERE
ORDER ។ SQL
relational databases Microsoft Access ។
a) SQL:
1. Ribbon, tab: Create
2. Other, Icon: Query Design
3. Show Table, Close
4. Query Tools: Design  Result, Icon: SQL
Management Information System SETEC University
Page 68 of 140 Chapter 3: Creating and Using Query
b) Run SQL:
- Ribbon, Query Tools: Design  Result, Icon:
Run
c) View SQL:
- Ribbon, tab: Home  View  SQL View
*** SELECT Statement
Instructs the Microsoft Jet database engine to return information from the database as a set
of records.
Syntax :
SELECT [predicate] { * | table.* | [table.]field1 [AS alias1] [, [table.]field2 [AS alias2] [, ...]]}
FROM tableexpression [, ...] [IN externaldatabase]
[WHERE... ]
[GROUP BY... ]
[HAVING... ]
[ORDER BY... ]
[WITH OWNERACCESS OPTION]
SETEC University Management Information System
Chapter 3: Creating and Using Query Page 69 of 140
The SELECT statement has these parts:
Part Description
Predicate One of the following predicates: ALL, DISTINCT, DISTINCTROW, or
TOP. You use the predicate to restrict the number of records returned. If
none is specified, the default is ALL.
* Specifies that all fields from the specified table or tables are selected.
Table The name of the table containing the fields from which records are
selected.
field1, field2 The names of the fields containing the data you want to retrieve. If you
include more than one field, they are retrieved in the order listed.
alias1, alias2 The names to use as column headers instead of the original column
names in table.
tableexpression The name of the table or tables containing the data you want to retrieve.
externaldatabase The name of the database containing the tables in tableexpression if
they are not in the current database.
Lab: queries SQL Statement:
1. database Northwind.accdb
2. SQL :
a. ustom rID, ont t m A r ss t l ustom rs ។
b. ProductID, ProductName, UnitPrice UnitsInStock ១
UnitsInStock table: Products ។
c. ro u t m , Unit ri UnitsInSto k table: Products
stock ៥ (UnitPrice) ២ ។
d. Or rID, Or rD t , Fr ight Ship m table: Orders
(Freight) ៣ ៤ ។
e. L st m First m table: Employees sort
Descending LastName ។
Management Information System SETEC University
Page 70 of 140 Chapter 3: Creating and Using Query
f. ២
table: [Order Details] ។
g. t l Or rs ។
h. OrderID,
១ Group by: OrderID t l Or r D t ils ។
i. Sort: Ascending
CompanyName ។
j. ustom rID, ont t m omp ny m
Subquery ។
k. ContactName, Address Country table: Customers, order by
Country, ContactName ។
*****End of Chapter 3*****
SETEC University Management Information System
Chapter 4: Creating and Using Form Page 71 of 140
Chapter 4
Creating and Using Form
អ្វីដៅជា Form?
Form Object MS-Access interface
table query ។
4.1. Form Form tool:
1. Navigation Pane, table query Form
2. Ribbon, tab: Create  Form, icon: Form
3. Access form Layout view :
Management Information System SETEC University
Page 72 of 140 Chapter 4: Creating and Using Form
4. Save save form
5. OK
4.2. View form:
1. Navigation Pane, Double-click form form
view Form View:
SETEC University Management Information System
Chapter 4: Creating and Using Form Page 73 of 140
2. Ribbon, tab: Home  Views, icon: View
: icons Status bar
- Form View: user ។
Management Information System SETEC University
Page 74 of 140 Chapter 4: Creating and Using Form
- Layout View: form (formatting)
។
- Design View: form (formatting)
Layout View ។
4.3. Form Split Form tool
1. Navigation Pane, table query Form
SETEC University Management Information System
Chapter 4: Creating and Using Form Page 75 of 140
2. Ribbon, tab: Create  Forms, icon: Split Form
3. Access form Layout View :
Form View
Datasheet View
Management Information System SETEC University
Page 76 of 140 Chapter 4: Creating and Using Form
4.4. Form Multiple Items tool:
1. Navigation Pane, table query Form
2. Ribbon, tab: Create  Form, icon: Multiple Items
3. Access form Layout View :
SETEC University Management Information System
Chapter 4: Creating and Using Form Page 77 of 140
4.5. Form Wizard
1. Ribbon, tab: Create  Form, More Forms 
Form Wizard
2. Wizard :
3. “T l s u ri s” , t l query
4. List “Av il l Fi l s”, fi l s form 
Next
Management Information System SETEC University
Page 78 of 140 Chapter 4: Creating and Using Form
5. layout form olumn r, T ul r, D t sh t, … 
Next
6. style form Access 2003, Access 2007, Apex, ... 
Next
SETEC University Management Information System
Chapter 4: Creating and Using Form Page 79 of 140
7. form title bar  “Op n th form to vi w or nt r
information.” Finish
4.6. form Blank Form tool:
1. Ribbon, Create  Forms, icon: Blank Form
2. Layout View Field List pane
:
Management Information System SETEC University
Page 80 of 140 Chapter 4: Creating and Using Form
3. Field List pane, (+) table fields
table
4. Double-click field form ។
fields key: Ctrl +
fields ។
5. tools Control tab: Format Logo, ,
form
SETEC University Management Information System
Chapter 4: Creating and Using Form Page 81 of 140
6. control form:
- Design view Right-click form  Design View
- Ribbon, tab: Design  tools Controls
4.7. control form:
1. form Design View  control
2. Right-click control  Layout 
Remove
3. Mouse pointer Controls
Management Information System SETEC University
Page 82 of 140 Chapter 4: Creating and Using Form
4. Control Mouse pointer
Controls
4.8. form :
Cursor field field
- Tab: Cursor field
- Shift + Tab: Cursor
- Ctrl + Home: Cursor record ១ Form
- Ctrl + End: Cursor record Form
SETEC University Management Information System
Chapter 4: Creating and Using Form Page 83 of 140
4.9. Main form Subform
Main form Subform
tables One-to-Many ។ Main form
table One Subform
table Many ។
Main form Columnar Form Subform Tabular
Form Datasheet Form
 form Subform Form Wizard
1. Ribbon, tab: Create  Forms, icon: More Forms  Form
Wizard
2. window Form Wizard :
3. Tables/Queries, table/query Main form
4. Double-click fields Main form
5. Wizard Tables/Queries,
table/query Subform
6. Double-click fields Subform
Management Information System SETEC University
Page 84 of 140 Chapter 4: Creating and Using Form
7. Next
8.  “Form
with su form s ”
9. Next
SETEC University Management Information System
Chapter 4: Creating and Using Form Page 85 of 140
10. layout subform : Tabular Datasheet
11. Next
12. style  Next
Management Information System SETEC University
Page 86 of 140 Chapter 4: Creating and Using Form
13. Main form Subform  “Op n th form to vi w
or nt r inform tion”
14. Finish
 Subform form
1. Main form Columnar
SETEC University Management Information System
Chapter 4: Creating and Using Form Page 87 of 140
2. Subform Tabular Form Datasheet Form
3. View main form Design View
4. Ribbon, tab: Design  Controls, icon: Use Control
Wizards
5. Navigation Pane, Subform Detail Main
form design
Management Information System SETEC University
Page 88 of 140 Chapter 4: Creating and Using Form
6. Access Subform Main form Relationship
Database ។
*** Access Subform Main form :
1. Navigation Pane, Right-click Main form  Design
2. form design, Subform
3. Ribbon, tab: Design Form Design Tools
 Tools, icon: Property Sheet
4. Property Sheet, tab: Data Properties
- Source Object: form Subform
SETEC University Management Information System
Chapter 4: Creating and Using Form Page 89 of 140
- Linked Master Field: Field (Primary key) Main form
Subform
- Linked Child Field: Field (Foreign key) Subform
Main form
5. View form Form View
Lab: Create Main form and Subform
1. Main form table: Customers
2. Subform table: Orders
3. Subform Main form
4.10. Visual Basic for Application(VBA):
V A Microsoft Visual Basic code
Windows
Application Microsoft ។
a. What is Object?
Object … ។
MS-Access Form, Object Control
Management Information System SETEC University
Page 90 of 140 Chapter 4: Creating and Using Form
- Text Box : Control
keyboard
- Label : Control Control
- Command Button : Control button
event
- h k ox Control check
uncheck
- Option Button : Control
ន ។
a.1. What is Property?
Property Object Control Form MS-
Access ។ rop rti s ontrols form
.Left : form
.Top : form
.Height: Control
.Width: Control
a.2. What is Method?
Method object ។
ObjectName.MethodName
E.g. :
txtFirstName.SetFocus
Me!txtLastName.Undo
rs.MoveNext
rs.MoveFirst
a.3. What is Event?
Event (Procedure)
user program code ។
E.g.:
Private Sub btnOK_Click()
Statements…
End Sub
SETEC University Management Information System
Chapter 4: Creating and Using Form Page 91 of 140
Private Sub Form_Load()
Statements…
End Sub
Private Sub txtFirstName_GotFocus()
Statements…
End Sub
b. form Design view
Ribbon, Tab: Create  Form Design
c. Code vi w o form
View form Design View  Form Design Tools, Tab: Design 
View Code
d. event control
Click control  Property windows, tab: Event 
event button
: Right-click control  uil Ev nt… Code Builder  OK
Lab: Form Code
1. Form
2. Code Editor, code
Private Sub btnOK_Click()
txtFirstName.Value = "Sabay"
txtLastName.Value = "Sok"
txtAddress.Value = "Bokor mountain"
End Sub
Private Sub btnClear_Click()
txtFirstName.Value = ""
txtLastName.Value = ""
txtAddress.Value = ""
txtFirstName.SetFocus
End Sub
txtFirstName
txtLastName
txtAddress
btnOK
btnClear
Management Information System SETEC University
Page 92 of 140 Chapter 4: Creating and Using Form
4.11. Introduction to Variables:
Variable memory
application ។ variable
memory ។
E.g.1:
Private Sub Detail_Click()
SomeColor = vbRed
Detail.BackColor = SomeColor
End Sub
- (declare) variable Dim
variable ។
Dim VariableName
E.g.:
Private Sub Form_Load()
Dim thisVar
thisVar = 15
MsgBox thisVar
End Sub
- Option Explicit: variable
(Error) ។
E.g.:
Private Sub Form_Load()
Dim thisVar
thisVar = 15
MsgBox thisInt '<-- Note the misspelled "thisInt"
End Sub
Option Explicit
Code Builder variable
variable ។
E.g. : Option Explicit
Private Sub Form_Load()
.....
End Sub
SETEC University Management Information System
Chapter 4: Creating and Using Form Page 93 of 140
- Option Explicit Code Builder:
1. menu Microsoft Visual Basic, Tools  Option…
2. tab: Editor  Code Settings, check h k ox “
R quir V ri l D l r tion”
4.12. Data Type:
Data Type variable ។
Dim VariableName As DataType
Or: Dim VariableName1 As DataType1, VariableName2 As
DataType2
Dim VariableName3 As DataType3
E.g. : Dim StudentName As Byte
Dim CountryName As String
- :
Data
Type
Description (Range)
Byte 1-byte binary data (0 to 255)
Integer 2-byte integer (– 32,768 to 32,767)
Long 4-byte integer (– 2,147,483,648 to 2,147,483,647)
Single
4-byte floating-
point number
(– 3.402823E38 to – 1.401298E
– 45 (negative values))
1.401298E – 45 to 3.402823E38 (positive values)
Double
8-byte floating-
point number
(– 1.79769313486231E308 to
– 4.94065645841247E – 324 (negative values))
4.94065645841247E – 324 to
1.79769313486231E308 (positive values)
Currency
8-byte number
with fixed decimal
point
(– 922,337,203,685,477.5808 to
922,337,203,685,477.5807)
String
String of
characters
(Zero to approximately two billion
characters)
Date
8-byte date/time
value
(January 1, 100 to
December 31, 9999)
- variable (Prefix)
variable
Management Information System SETEC University
Page 94 of 140 Chapter 4: Creating and Using Form
Data Type Prefix Example
Boolean bln blnFound
Byte byt bytTracks
Date/Time dtm dteStartOfShift
Double dbl dblDistance
Error err errCantOpen
Integer int intNbrOfStudents
Long lng lngPopulation
Object obj objConnection
Single sng sngAge
String str strCountryName
Currency cur curHourlySalary
Variant var varFullName
- Functions
CBool(): convert Boolean
CStr(): convert String
CByte(): convert Byte
(Small number)
Int convert Integer
Lng convert Long
CSng convert Single
CDbl: convert Double
ur convert Currency
D t convert Date
- Constant: variable ។
Const VariableName = Value
E.g. : Const conPI = 3.14159265359
vbCrLf (Carriage Return-Line Feed Constant) : constant
text ។
- Static keyword variable function
sub procedure ។ variable keyword:
Static memory
function sub procedure ។
SETEC University Management Information System
Chapter 4: Creating and Using Form Page 95 of 140
E.g. : Sub Calculate()
Static intVar As Integer
intVar = intVar + 1
MsgBox intVar
End Sub
Private Sub btnCalculate_Click()
Call Calculate
End Sub
Lab: Data Type:
1. form Design View
2. form  Property windows, tab: Event  event
“On li k” button
3. code
Private Sub Detail_Click()
Dim strName As String,intYearBorn As Integer
Dim intAge As Integer
strName = InputBox("Your name: ")
intYearBorn = InputBox("Year borned: ")
intAge = Format(Now(), "yyyy") - intYearBorn
MsgBox "Hello " & strName & vbCrLf & _
"you are " & intAge & " years old."
End Sub
4. form Design View A ontrol omm n utton :
- Caption: Calculate
- Name: btnCalculate
5. code
Sub Calculate()
Static intVar As Integer
intVar = intVar + 1
MsgBox intVar
End Sub
- event: On Click button: Calculate code:
Private Sub btnCalculate_Click()
Call Calculate
End Sub
6. Save form “frmSt ti V ri l ”
Management Information System SETEC University
Page 96 of 140 Chapter 4: Creating and Using Form
*** MsgBox function: (See help: MsgBox Function)
message dialog box click button user
constant button user click ។
MsgBox(prompt[, buttons Or icon] [, title])
- prompt: string expression message dialog
box ។
- button: buttons prompt
Constant Value Description
vbOKOnly 0 Display OK button only.
vbOKCancel 1 Display OK and Cancel buttons.
vbAbortRetryIgnore 2 Display Abort, Retry, and Ignore buttons.
vbYesNoCancel 3 Display Yes, No, and Cancel buttons.
vbYesNo 4 Display Yes and No buttons.
vbRetryCancel 5 Display Retry and Cancel buttons.
vbCritical 16 Display Critical Message icon.
vbQuestion 32 Display Warning Query icon.
vbExclamation 48 Display Warning Message icon.
vbInformation 64 Display Information Message icon.
vbDefaultButton1 0 First button is default.
vbDefaultButton2 256 Second button is default.
vbDefaultButton3 512 Third button is default.
vbDefaultButton4 768 Fourth button is default.
Constants VBA constants
code ។
icon
title
prompt
buttons
SETEC University Management Information System
Chapter 4: Creating and Using Form Page 97 of 140
If the user click The function returns Numeric Value
vbOK 1
vbCancel 2
vbAbort 3
vbRetry 4
vbIgnore 5
vbYes 6
vbNo 7
- titl string Title bar Message Box ។
E.g. :
Private Sub Detail_Click()
MsgBox "Do you really want to delete this record?", _
vbYesNoCancel Or vbQuestion, "Confirmation"
End Sub
- buttons
MsgBox
Dim x As Integer
x = MsgBox("Do you really want to delete this record?", _
vbYesNoCancel + vbQuestion, "Confirmation")
code MsgBox buttons
Yes, No Cancel ។ button: Yes
constant vbYes=6 x ។
*** InputBox Function:
message dialog box text click
button user string text box ។
InputBox(prompt[, title] [, default])
Management Information System SETEC University
Page 98 of 140 Chapter 4: Creating and Using Form
- prompt title: Message Box ។
- f ult text text box user
។
E.g. :
Private Sub Form_Load()
Dim x As Integer, y As Integer
Dim sum As Integer
x = InputBox("Please enter value of x", "Enter value of x")
y = InputBox("Please enter value of y", "Enter value of y")
sum = x + y
MsgBox "The sum of " & x & " and " & y & " is " & sum,
,"Result"
End Sub
SETEC University Management Information System
Chapter 4: Creating and Using Form Page 99 of 140
Lab : Form Code:
1. form
- Add buttons properties
Name Caption Events
btnSum Sum On_Click
btnSubtract Subtract On_Click
btnMultiply Multiply On_Click
btnDivide Divide On_Click
- click buttons , access InputBox user
(x y) ។
2. code
Option Compare Database
Option Explicit
Private Sub btnDivide_Click()
Dim x As Integer, y As Integer
Dim divide As Integer
x = InputBox("Please enter value of x", "Enter value of x")
y = InputBox("Please enter value of y", "Enter value of y")
divide = x / y
MsgBox "The division of " & x & " and " & y & " is " & _
divide, , "Result"
End Sub
Private Sub btnMutiply_Click()
Dim x As Integer, y As Integer
Dim multiply As Integer
x = InputBox("Please enter value of x", "Enter value of x")
y = InputBox("Please enter value of y", "Enter value of y")
multiply = x * y
MsgBox "The multiplication of " & x & " and " & y & " is " &
multiply, , "Result"
End Sub
Management Information System SETEC University
Page 100 of 140 Chapter 4: Creating and Using Form
Private Sub btnSubtract_Click()
Dim x As Integer, y As Integer
Dim subtract As Integer
x = InputBox("Please enter value of x", "Enter value of x")
y = InputBox("Please enter value of y", "Enter value of y")
subtract = x - y
MsgBox "The subtract of " & x & " and " & y & " is " &
subtract, , "Result"
End Sub
Private Sub btnSum_Click()
Dim x As Integer, y As Integer
Dim sum As Integer
x = InputBox("Please enter value of x", "Enter value of x")
y = InputBox("Please enter value of y", "Enter value of y")
sum = x + y
MsgBox "The sum of " & x & " and " & y & " is " & sum, ,
"Result"
End Sub
4.13. Introduction to Procedures:
Procedure code program
។ ro ur s VBA Sub
Procedure Function Procedure ។ procedures Function
Procedure return Sub Procedure return
(Call) ។
4.13.1. Sub Procedure:
Sub ProcedureName([Arguments])
Statements…
End Sub
E.g. :
Sub Multiply()
Dim x As Integer, y As Integer
Dim result As Integer
x = txtValue1
y = txtValue2
result = x * y
txtResult = result
End Sub
- (Call) Sub Procedure
Call ProcedureName([Arguments])
ProcedureName [Arguments]
SETEC University Management Information System
Chapter 4: Creating and Using Form Page 101 of 140
E.g. :
Private Sub btnCalculate_Click()
Call Multiply
End Sub
- Sub Procedure Arguments
Sub Multiply(x As Integer, y As Integer)
Dim result As Integer
result = x * y
txtResult = result
End Sub
Private Sub btnCalculate_Click()
Call Multiply(txtValue1, txtValue2)
End Sub
4.13.2. Function Procedure:
Function FuntionName([Arguments]) As DataType
Statements…
End Function
- Function Procedure Sub Procedure return
As DataType
return ។
E.g. :
Function Divide() As Integer
Dim x As Integer, y As Integer
x = txtValue1
y = txtValue2
Divide = x / y
End Function
- Function Procedure ។
statements Sub Procedure Sub
Procedure ។ return text box
variable ។
E.g. :
Private Sub btnCalculate_Click()
txtResult = Divide
End Sub
Management Information System SETEC University
Page 102 of 140 Chapter 4: Creating and Using Form
Lab: Sub Procedure:
1. form
2. Sub Procedure
3. Sub Procedure
4. click button: Calculate ។
5. click button: New clear text box ។
Sub SquareSolution()
Dim dblSide As Double
Dim dblPerimeter, dblArea As Double
dblSide = txtSide
dblPerimeter = dblSide * 4
dblArea = dblSide * dblSide
txtSqPerimeter = dblPerimeter
txtSqArea = dblArea
End Sub
Private Sub RectangleSolution()
Dim dblLength, dblHeight As Double
Dim dblPerimeter, dblArea As Double
dblLength = txtLength
dblHeight = txtHeight
dblPerimeter = (dblLength + dblHeight) * 2
dblArea = dblLength * dblHeight
txtRecPerimeter = dblPerimeter
txtRecArea = dblArea
End Sub
SETEC University Management Information System
Chapter 4: Creating and Using Form Page 103 of 140
Private Sub btnCalculateRec_Click()
RectangleSolution
End Sub
Private Sub btnCalculateSqare_Click()
Call SquareSolution
End Sub
Private Sub btnSqNew_Click()
txtSide = ""
txtSqPerimeter = ""
txtSqArea = ""
txtSide.SetFocus
End Sub
Private Sub btnRecNew_Click()
txtLength = ""
txtHeight = ""
txtRecPerimeter = ""
txtRecArea = ""
txtLength.SetFocus
End Sub
Homework: Function Procedure:
Lab Function Procedure ។
4.13.3. Procedure Arguments:
-
Sub ProcedureName(Var1 As Datatype, Var2 As Datatype,…)
Statements
End Sub
Function FunctionName(Var1 As Datatype, Var2 As Datatype,…) _
As Datatype
Statements
End Function
E.g. 1 Function Procedure ។
Function CubeArea(Side As Double) As Double
CubeArea = Side * Side * 6
End Function
Function CubeVolume(Side As Double) As Double
CubeVolume = Side * Side * Side
End Function
- Call Function ro ur Arguments
Private Sub btnCalculate_Click()
txtArea = CubeArea(txtSide)
txtVolume = CubeVolume(txtSide)
End Sub
Parameter
Management Information System SETEC University
Page 104 of 140 Chapter 4: Creating and Using Form
Lab: Procedures with Arguments:
1. Sub Procedure
Sub SolveEllipse(SmallRadius As Double, LargeRadius As
Double)
Dim dblCircum As Double
Dim dblArea As Double
dblCircum = (SmallRadius + LargeRadius) * 2
dblArea = SmallRadius * LargeRadius * 3.14159 ‘2R
txtEllipseCircumference = dblCircum
txtEllipseArea = dblArea
End Sub
2. Function Procedures
Function BoxArea(dblLength As Double, _
dblHeight As Double, _
dblWidth As Double) As Double
Dim Area As Double
Area = 2 * ((dblLength * dblHeight) + _
(dblHeight * dblWidth) + _
(dblLength * dblWidth) _
)
BoxArea = Area
End Function
Function BoxVolume(dblLength As Double, _
dblHeight As Double, _
dblWidth As Double) As Double
Dim Volume As Double
Volume = dblLength * dblHeight * dblHeight
BoxVolume = Volume
End Function
Homework
HW1: Sub Procedure
១ HourW g ។
txtHours
txtHWage
txtResult
btnE&xit
SETEC University Management Information System
Chapter 4: Creating and Using Form Page 105 of 140
Private Sub txtResult_GotFocus()
Dim dblHours As Double
Dim dblHWage As Double
dblHours = txtHours
dblHWage = txtHWage
CalcAndShowSalary dblHours, dblHWage
End Sub
Sub CalcAndShowSalary(Hours As Double, HWage As Double)
Dim dblResult As Double
dblResult = Hours * HWage
txtResult = dblResult
End Sub
Private Sub btnExit_Click()
DoCmd.Close
End Sub
HW2: Function Procedure discount
(Marked Price) (Discount Rate) ។
Function CalculateNetPrice(DiscountRate As Double) As Currency
Dim OrigPrice As Double
OrigPrice = CCur(txtMarkedPrice)
CalculateNetPrice = OrigPrice - OrigPrice * DiscountRate
End Function
Private Sub cmdCalculate_Click()
Dim dblDiscount Double
dblDiscount = CDbl(txtDiscountRate)
txtNetPrice = CalculateNetPrice(dblDiscount)
End Sub
Management Information System SETEC University
Page 106 of 140 Chapter 4: Creating and Using Form
4.14. Conditional Statements
- Here is a summary table of the logical operators we have studied:
Operator Meaning Example Opposite
= Equality to a = b Not
Not Not equal to 12 <> 7 =
< Less than 25 < 84 >=
<= Less than or equal to Cab <= Tab >
> Greater than 248 > 55 <=
>= Greater than or equal to Val1 >= Val2 <
- The If…Then Statement
If Condition Then Statement
:
If Condition Then
Statement1
Statement2
………………
End If
- The If…Then…Else Statement
If Condition Then
Statement1
Else
Statement2
End If
- The If…Then…ElseIf Statement
If Condition1 Then
Statement1
Else If Condition2 Then
Statement2
Else If Condition3 Then
Statement3
Else
Statement4
End If
SETEC University Management Information System
Chapter 4: Creating and Using Form Page 107 of 140
Lab: Conditional Statements:
1. Password Form frmLogin
Textboxs:
- txtUserName
- txtPassword, Inputmask: Password
Command buttons:
- btnLogin, Caption: L&ogin
- btnClose, Caption: &Close
2. code event On_Click button: Login
Private Sub btnLogin_Click()
If txtUserName = "Sabay" And txtPassword = "1234" Then
MsgBox "Welcome to my application"
DoCmd.OpenForm "frmHourWage"
Else
txtPassword = ""
txtUserName = ""
txtUserName.SetFocus
End If
End Sub
3. code event On_Click button: Login
Private Sub btnClose_Click()
DoCmd.Close
End Sub
4.15. Counting and Looping Structures:
Looping Structures computer
(Statements) ។
- Th Do Whil …Loop
Do While Condition
Statement(s)
Loop
Management Information System SETEC University
Page 108 of 140 Chapter 4: Creating and Using Form
E.g.: Private Sub cmdCounter_Click()
Dim Number As Integer
Do While Number < 46
MsgBox CStr(Number)
Number = Number + 4
Loop
MsgBox "Counting Stopped at " & CStr(Number)
End Sub
- Th Do…Loop Whil
Do
Statement(s)
Loop While Condition
E.g.: Private Sub cmdCounter_Click()
Dim Answer As String
Do
Answer = CStr(InputBox("Are we there yet(1=Yes/0=No)?",
"Counter", "1"))
Loop While Answer <> "1"
MsgBox "Wonderful, we have arrived"
End Sub
- Th Do Until…Loop
Do Until Condition
Statement(s)
Loop
E.g.:
Private Sub cmdCounter_Click()
Dim Answer As String
Do Until (Answer = "1")
Answer = InputBox("Are we there yet (1=Yes/0=No)?", _
"Counter", "1")
Loop
MsgBox "Wonderful, we have arrived"
End Sub
- Th Do…Loop Until
Do
Statement(s)
Loop Until Condition
- Th For… ext:
For Counter = Start To End Step Increment
Statement(s)
Next Counter
Note: To stop an endless loop, press ESC or CTRL+BREAK.
SETEC University Management Information System
Chapter 4: Creating and Using Form Page 109 of 140
4.16. Data Access Objects(DAO)
1. What is DAO?
DAO Programming interface Microsoft Visual Basic
database Microsoft Microsoft Access database ។
2. Recordset
object DAO records table
query database ។
3. Database Object :
Dim DatabaseName AS DAO.Database
E.g. : Dim db AS DAO.Database
4. Recordset Object :
Dim RecordsetName AS DAO.Recordset
E.g. : Dim rs AS DAO.Recordset
5. Database Object :
Set db = CurrentDb() : Database Object ដ ើមបីភ្ជ
ា ប់ Database
។
Set db = DAO.OpenData s “ thFil m .m ” Database Object
Database ។
E.g. :
Set db = DAO.OpenDatab s “D My DatabasesStudentDB.acc ”
6. Recordset Object
S t rs = .Op nR or s t “T l |qu ry”, R or Typ
*RecordType:
- dbOpenDynaset: Open in Dynaset
- dbOpenTable: Open in table (have index)
- dbOpenSnapShot: Open in snapshot (read only)
Management Information System SETEC University
Page 110 of 140 Chapter 4: Creating and Using Form
Lab1: DAO Form :
- Form :
- Database Recordset :
Option Explicit
Dim db As DAO.Database
Dim rs As DAO.Recordset
Sub showDT()
txtSubjectID.Value = rs.Fields("SubjectID")
txtSubjectName.Value = rs.Fields("SubjectName")
txtDescription.Value = rs.Fields("Description")
End Sub
- Database Recordset Form_Load() :
Private Sub Form_Load()
Dim strSQL As String
strSQL = "Select * from tblSubjects"
Set db = CurrentDb
Set rs = db.OpenRecordset(strSQL)
Call showDT
End Sub
- code btnFirst (event: On_Click) record ១:
Private Sub btnFirst_Click()
rs.MoveFirst
Call showDT
End Sub
- code btnLast (event: On_Click) record :
Private Sub btnLast_Click()
rs.MoveLast
Call showDT
End Sub
txtSubjectID
txtSubjectName
txtDescription
btnFirst
btnPrevious
btnNext
btnLast
SETEC University Management Information System
Chapter 4: Creating and Using Form Page 111 of 140
- code btnNext (event: On_Click) record :
Private Sub btnNext_Click()
rs.MoveNext
If Not rs.EOF Then
Call showDT
Else
MsgBox "No more record"
rs.MovePrevious
End If
End Sub
- code btnPrevious (event: On_Click) record :
Private Sub btnPrevious_Click()
rs.MovePrevious
If Not rs.BOF Then
Call showDT
Else
MsgBox "First record reached"
rs.MoveNext
End If
End Sub
Lab 2: records :
- code btnSearch (event: On_Click) records:
Private Sub btnSearch_Click()
Dim strCriteria As String
strCriteria = "Select * from tblSubjects Where _
SubjectName='" _
& InputBox("Input SubjectName:") & "'"
Set db = CurrentDb
Set rs = db.OpenRecordset(strCriteria)
If rs.EOF Then
MsgBox "No record found!", vbInformation
Else
Call showDT
End If
End Sub
btnSearch
btnClear
Management Information System SETEC University
Page 112 of 140 Chapter 4: Creating and Using Form
Lab 3: Add record :
- code btnAdd (event: On_Click) Add records:
Private Sub btnAdd_Click()
Dim intSubjectID As Integer
Dim strSubjectName As String
Dim strDescription As String
intSubjectID = InputBox("Input Subject ID:")
strSubjectName = InputBox("Input Subject Name:")
strDescription = InputBox("Input Description:")
With rs
.AddNew
!SubjectID = intSubjectID
!SubjectName = strSubjectName
!Description = strDescription
.Update
.Close
End With
End Sub
Lap 4: record :
- code btnDelete (event: On_Click) Delete records:
Private Sub btnDelete_Click()
If MsgBox("Are you sure you want to delete this record?",
vbYesNo, "Delete record") = vbYes Then
rs.Delete
Call btnPrevious_Click
Else
Exit Sub
End If
End Sub
btnAdd
btnDelete
SETEC University Management Information System
Chapter 4: Creating and Using Form Page 113 of 140
Lab 5: Update record:
- code btnAdd (event: On_Click) Add records:
Private Sub btnUpdate_Click()
With rs
.Edit
!SubjectID = txtSubjectID
!SubjectName = txtSubjectName
!Description = txtDescription
.Update
End With
End Sub
*****End of Chapter 4*****
btnUpdate
Management Information System SETEC University
Page 114 of 140 Chapter 5: Creating and Using Report
Chapter 5
Creating and Using Report
Report?
Report Object MS-Access ដេញពី table
query ។
5.1. R port Report tool:
1. Navigation Pane, Table Query
Report
2. Ribbon, tab: Create  Reports,
icon: Report
Report Layout View :
3. Save Save report
5.2. View Report
1. Navigation Pane, Double-click Report Report
view Report View
SETEC University Management Information System
Chapter 5: Creating and Using Report Page 115 of 140
2. Ribbon, tab: Home  Views, icon: View
: icons Status bar
- Report View: Report Print
Report Clipboard
Management Information System SETEC University
Page 116 of 140 Chapter 5: Creating and Using Report
- Print Preview: Report Print
- Layout View: Report (design)
។
- Design View: Report (formatting)
Layout View ។
SETEC University Management Information System
Chapter 5: Creating and Using Report Page 117 of 140
5.3. R port Report Wizard
1. Ribbon, tab: Create  Report,
icon: Report Wizard ។
Wizard :
2. “T l s u ri s” , t l query
3. List “Av il l Fi l s”, fields Report ។
Report fields table query
“T l s u ri s” table/query
fields ។
4. Next
Management Information System SETEC University
Page 118 of 140 Chapter 5: Creating and Using Report
5. field grouping levels  Next
6. fields (Sort) Detail records 
Next
SETEC University Management Information System
Chapter 5: Creating and Using Report Page 119 of 140
7. Layout Orientation Report
- Stepped:
- Block:
Management Information System SETEC University
Page 120 of 140 Chapter 5: Creating and Using Report
- Outline:
8. Next
9. Style  Next
SETEC University Management Information System
Chapter 5: Creating and Using Report Page 121 of 140
10. Report  “ r vi w th r port”
11. Finish
5.4. Label Label Wizard
1. Navigation Pane, Double-click table query
Label
2. Ribbon, tab: Create  Reports,
icon: Label
3. Label Wizard
:
Management Information System SETEC University
Page 122 of 140 Chapter 5: Creating and Using Report
4. Label  Next
5. Text Label  Next
6. fields mailing label  Next
SETEC University Management Information System
Chapter 5: Creating and Using Report Page 123 of 140
7. field (Sort)  Next
8. Report  “S th l ls s th y will look print ”
9. Finish
Management Information System SETEC University
Page 124 of 140 Chapter 5: Creating and Using Report
5.5. R port Blank Report tool:
1. Ribbon, tab: Create  Report,
icon: Blank Report
2. Field List pane, (+) Table
fields table
3. Double-click field Report ។
fields key: Ctrl +
fields ។
4. tools Control tab: Format
Logo, ,
Report ។
SETEC University Management Information System
Chapter 5: Creating and Using Report Page 125 of 140
5.6. Report Sections:
Report :
 Report Header: Report ។
Logo, ។
 Page Header ។
Report ។
 Group Header Records ។
Records ។
 Detail Row Record Source ។
 Group Footer: Records ។
(Aggregate Functions) ។
 Page Footer ។
។
 Report Footer: Report ។
Report ។
Management Information System SETEC University
Page 126 of 140 Chapter 5: Creating and Using Report
5.7. Grouped Report Report Wizard:
 Record Source:
1. Select Query tables: Customers Orders
fields:
2. Save query qryTotal Freight by Shipped Date
 Report Wizard:
1. Ribbon, tab: Create  Report, icon: Report Wizard
Wizard Report :
SETEC University Management Information System
Chapter 5: Creating and Using Report Page 127 of 140
2. Tables/Queries, table query Record
Source Report
3. list “Av il l Fi l s”, fields Report
 Next
4.  Next
Management Information System SETEC University
Page 128 of 140 Chapter 5: Creating and Using Report
5. field group
- field
(Data Type) Date/Time i on Grouping Options …
Grouping intervals
- OK
6. Next
SETEC University Management Information System
Chapter 5: Creating and Using Report Page 129 of 140
7. fields (Sort)
Detail records
- i on Summ ry Options …
-
Aggregate function (Sum, Avg, Min Max)
- OK
8. Next
Management Information System SETEC University
Page 130 of 140 Chapter 5: Creating and Using Report
9. Layout Orientation Report St pp , lo k, Outlin …
10. Next
11. Style  Next
SETEC University Management Information System
Chapter 5: Creating and Using Report Page 131 of 140
12. Report  “ r vi w th r port”
13. Finish
Lab: េូរបដ្កើត report មួយ ូេរូបខា្ដរោម ៖
Management Information System SETEC University
Page 132 of 140 Chapter 5: Creating and Using Report
Solution:
5.8. Homeworks
1. បដ្កើត tblCustomers ដ ើមបីផ្ទុកព័ត៌មានអ្ំពីអ្តិថិជន
2. បដ្កើត tblProducts ដ ើមបីផ្ទុកព័ត៌មានអ្ំពីផ្លិតផ្ល
3. បដ្កើត tblOrders ដ ើមបីផ្ទុកព័ត៌មានអ្ំពីោរបញ្ជ
ា ទិញទំនិញពីអ្តិថិជន
SETEC University Management Information System
Chapter 5: Creating and Using Report Page 133 of 140
4. បដ្កើត tblOrderDetails ដ ើមបីផ្ទុកព័ត៌មានបន្នែមអ្ំពីោរបញ្ជ
ា ទិញទំនិញពីអ្តិថិជន ដោយរួម
បញ្ចូលទំ្ទំនិញន្ លអ្តិថិជនទិញ ។
5. បដ្កើត relationships រវា្ tables :
6. បដ្កើត frmOrderDetailProductSub ដេញពី tblOrderDetail និ្ tblProducts រួេគណនារក
Sub Total និ្ Total ូេខា្ដរោម :
Management Information System SETEC University
Page 134 of 140 Chapter 5: Creating and Using Report
7. បដ្កើត frmOrders ដេញពី tblOrders រួេទញ Subform: frmOrderDetailProductSub ន្ ល
បានបដ្កើតរួេខា្ដលើោក់េូល ូេខា្ដរោម :
8. បដ្កើត frmCustomerOrder (Mainform) ដេញពី tblCustomers រពមទំ្គូស combobox
មួយសំរាប់ ន្សវ្រកតាមរយៈ ដ្
ម ោះអ្តិថិជន ។
a. សរដសរ code បដ្កើត event: After_Update ដលើ cboSearch ូេខា្ដរោម :
Private Sub cboSearch_AfterUpdate()
Dim SQL As String
SQL = "Select * from tblCustomers Where CustomerName='"
_
& cboSearch & "'"
Form_frmCustomerOrder.RecordSource = SQL
End Sub
b. ទញ frmOrder ន្ លបានបដ្កើតដ ើ្ខា្ដលើ ោក់ជា subform កនុ្ frmCustomerOrder
រួេគូស buttons ពីរ ូេរូបខា្ដរោម :
cboSearch
frmOrders
frmOrderDetailProducttSub
SETEC University Management Information System
Chapter 5: Creating and Using Report Page 135 of 140
c. សរដសរ code បដ្កើត event: On_Click ដលើ btnPreviewReport ូេខា្ដរោម :
Private Sub btnPreviewReport_Click()
DoCmd.OpenReport "rptCustomerOrder", acViewReport, , _
"CustomerID=" & Me.CustomerID
End Sub
d. សរដសរ code បដ្កើត event: On_Click ដលើ btnPrintReport ូេខា្ដរោម ៖
Private Sub btnPrintReport_Click()
DoCmd.OpenReport "rptCustomerOrder", acViewNormal, , _
"CustomerID=" & Me.CustomerID
End Sub
សំគាល់ៈ
- acViewReport: សំរាប់ បង្ហ
ា ញ report កនុ្ Print Preview
- acViewNormal: សំរាប់ print report
- េូរអ្នុវតតេំនុេ c និ្ d ដរោយដពលបដ្កើត report រួេ ។
9. បដ្កើត rptOrderDetailProductSub ដេញពី tblOrderDetail និ្ tblProducts រួេគណនារក Sub
Total និ្ Total ូេខា្ដរោម :
frmCustomerOrder
frmOrders
btnPrintReport
btnPreviewReport
Management Information System SETEC University
Page 136 of 140 Chapter 5: Creating and Using Report
10.បដ្កើត rptOrders ដេញពី tblOrders រួេទញ Subreport: rptOrderDetailProductSub ន្ ល
បានបដ្កើតរួេខា្ដលើោក់េូល ូេរូបខា្ដរោម :
11.បដ្កើត rptCustomerOrder (Mainreport) ដេញពី tblCustomers :
 ទញ rptOrder ន្ លបានបដ្កើតដ ើ្ខា្ដលើ ោក់ជា subreport កនុ្ rptCustomerOrder
ូេរូបខា្ដរោម :
rptOrders
rptOrderDetailProducttSub
SETEC University Management Information System
Chapter 5: Creating and Using Report Page 137 of 140
12.រដបៀបកំនត់ដលខដរៀ្ដោយបង្ហ
ា ញដោយសវ័យរបវតតន៍តាមរកុម (Over Group) :
a. ដបើក rptOrderDetailProductSub កនុ្ Design View រួេគូស textbox មួយដលើផ្ផ្ទ Detail
ដោយោក់ដ្
ម ោះ txtNo ូេខា្ដរោម :
rptCustomerOrder
rptOrders
Management Information System SETEC University
Page 138 of 140 Chapter 5: Creating and Using Report
b. កំនត់ property របស់ txtNo :
- Control Source: =1
- Running Sum: Over Group
***End of Chapter 5***

More Related Content

PDF
College Application Essay Sample Sp. Online assignment writing service.
PDF
Persuasive Essay Example - Raisa Te. Online assignment writing service.
PDF
Freelance Essay Writing Jobs. 40 Best Freelance Writing Jobs And ...
PDF
023 Service Learning Essay Letter Of Recommendatio
PDF
Writing An Essay About Myself Samples. Online assignment writing service.
PDF
Expository Essay Introduction. How To Wr
PDF
High School Fun-Packed Experience Free Essay Ex
PDF
49 Common App Transfer Essay Examples Image - A
College Application Essay Sample Sp. Online assignment writing service.
Persuasive Essay Example - Raisa Te. Online assignment writing service.
Freelance Essay Writing Jobs. 40 Best Freelance Writing Jobs And ...
023 Service Learning Essay Letter Of Recommendatio
Writing An Essay About Myself Samples. Online assignment writing service.
Expository Essay Introduction. How To Wr
High School Fun-Packed Experience Free Essay Ex
49 Common App Transfer Essay Examples Image - A

More from Mandy Brown (20)

PDF
How To Cite Without Author - Textbooks Course Materials - APA Guide ...
PDF
Three Research Paper Introduction Examples Learn How To Initiate And ...
PDF
Definition Essay Cheap Essay Writin. Online assignment writing service.
PDF
Child Observation Essay Telegraph. Online assignment writing service.
PDF
Resources To Print Robots Creative Writing Club - Me
PDF
Example Position Paper Mun Sample Position Paper
PDF
Great Quotes Between The Lines. Online assignment writing service.
PDF
Travel Writing How To Write A Powerful (Not Boring) Tra
PDF
Good Research Paper Examples. Effective Resea
PDF
Connecting Words For Essays. Linking Words For
PDF
Examples Of How To Start An Essay Introduction. How To Start An Essay ...
PDF
How To Write Short Songs For Beginners 14 Steps - Instr
PDF
IELTS Writing Tips And Tricks The Ultimate Guide - YouTube
PDF
How To Write A Research Essay Example. How To Wr
PDF
58 In Text Citation Example Quote. Online assignment writing service.
PDF
A PRACTICAL GUIDE ON BEING A PHOTOGRAPHER.pdf
PDF
Archives of Business Administration and Management.pdf
PDF
A Survey on Sentiment Analysis and Opinion Mining.pdf
PDF
Adam Smith The Wealth of Nations.pdf
PDF
13Essays In Philosophy And Yoga.pdf
How To Cite Without Author - Textbooks Course Materials - APA Guide ...
Three Research Paper Introduction Examples Learn How To Initiate And ...
Definition Essay Cheap Essay Writin. Online assignment writing service.
Child Observation Essay Telegraph. Online assignment writing service.
Resources To Print Robots Creative Writing Club - Me
Example Position Paper Mun Sample Position Paper
Great Quotes Between The Lines. Online assignment writing service.
Travel Writing How To Write A Powerful (Not Boring) Tra
Good Research Paper Examples. Effective Resea
Connecting Words For Essays. Linking Words For
Examples Of How To Start An Essay Introduction. How To Start An Essay ...
How To Write Short Songs For Beginners 14 Steps - Instr
IELTS Writing Tips And Tricks The Ultimate Guide - YouTube
How To Write A Research Essay Example. How To Wr
58 In Text Citation Example Quote. Online assignment writing service.
A PRACTICAL GUIDE ON BEING A PHOTOGRAPHER.pdf
Archives of Business Administration and Management.pdf
A Survey on Sentiment Analysis and Opinion Mining.pdf
Adam Smith The Wealth of Nations.pdf
13Essays In Philosophy And Yoga.pdf
Ad

Recently uploaded (20)

PDF
Empowerment Technology for Senior High School Guide
DOCX
Cambridge-Practice-Tests-for-IELTS-12.docx
PDF
Τίμαιος είναι φιλοσοφικός διάλογος του Πλάτωνα
PDF
Complications of Minimal Access-Surgery.pdf
PDF
1.3 FINAL REVISED K-10 PE and Health CG 2023 Grades 4-10 (1).pdf
PDF
IGGE1 Understanding the Self1234567891011
PPTX
ELIAS-SEZIURE AND EPilepsy semmioan session.pptx
PPTX
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
PDF
advance database management system book.pdf
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PDF
International_Financial_Reporting_Standa.pdf
PDF
AI-driven educational solutions for real-life interventions in the Philippine...
PDF
Practical Manual AGRO-233 Principles and Practices of Natural Farming
PPTX
20th Century Theater, Methods, History.pptx
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PPTX
Virtual and Augmented Reality in Current Scenario
PPTX
History, Philosophy and sociology of education (1).pptx
PDF
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 2).pdf
DOC
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
PDF
FOISHS ANNUAL IMPLEMENTATION PLAN 2025.pdf
Empowerment Technology for Senior High School Guide
Cambridge-Practice-Tests-for-IELTS-12.docx
Τίμαιος είναι φιλοσοφικός διάλογος του Πλάτωνα
Complications of Minimal Access-Surgery.pdf
1.3 FINAL REVISED K-10 PE and Health CG 2023 Grades 4-10 (1).pdf
IGGE1 Understanding the Self1234567891011
ELIAS-SEZIURE AND EPilepsy semmioan session.pptx
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
advance database management system book.pdf
Chinmaya Tiranga quiz Grand Finale.pdf
International_Financial_Reporting_Standa.pdf
AI-driven educational solutions for real-life interventions in the Philippine...
Practical Manual AGRO-233 Principles and Practices of Natural Farming
20th Century Theater, Methods, History.pptx
202450812 BayCHI UCSC-SV 20250812 v17.pptx
Virtual and Augmented Reality in Current Scenario
History, Philosophy and sociology of education (1).pptx
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 2).pdf
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
FOISHS ANNUAL IMPLEMENTATION PLAN 2025.pdf
Ad

Access 2007 Notes-All Chapters.pdf

  • 1. SETEC University Management Information System Table of Contents I Table of Contents Chapter 1 .............................................................................................................................................1 Introduction to MS-Access 2007.........................................................................................................1 1.1. របបៀបបបើកកម្មវិធី MS-Access 2007: ...................................................................................1 1.2. របបៀបបិទកម្មវិធី MS-Access 2007 ......................................................................................3 1.3. របបៀបបប្កើត Database ថ្មី .....................................................................................................3 1.4. របបៀបបបើក Database ដែលមានស្រាប់................................................................................5 Chapter 2 .............................................................................................................................................6 Creating and Using Table....................................................................................................................6 2.1. របបៀបបប្កើត Table ថ្មីែំបូ្..................................................................................................6 2.2. របបៀបបប្កើត Table ថ្មីបដនែម្................................................................................................7 2.3. របបៀបបប្កើត Table ថ្មីបដនែម្ បោយប្បើ Table Templates...................................................7 2.4. របបៀបបដនែម្ Field/Column ចូលកនុ្ Table.........................................................................7 2.5. របបៀបបដនែម្ Field/Column ចូលកនុ្ Table បោយប្បើ Field Templates ............................7 2.6. របបៀបបដនែម្ Field/Column ពី Table បផេ្បទៀតកនុ្ Datasheet View:...............................8 2.7. របបៀបលប់ Field/Column បចញពី Table កនុ្ Datasheet View............................................8 2.8. របបៀបបប្កើត Table កនុ្ Design View..................................................................................9 2.9. Primary Key: ......................................................................................................................14 2.10. Import Table:......................................................................................................................14 2.11. Export Tables .....................................................................................................................21 2.12. ភ្ជ ា ប់បៅកាន់ Table (Link Table): ......................................................................................22 2.13. បប្កើត Lookup Wizard .......................................................................................................24 2.14. Relationships:.....................................................................................................................30 2.15. ការកំនត់ោក់ Password:....................................................................................................33 Chapter 3 ...........................................................................................................................................36 Creating and Using Query.................................................................................................................36 3.1. បប្កើត Select Query បោយប្បើ wizard:.............................................................................37 3.2. របបៀប Run query: ..............................................................................................................39 3.3. បប្កើត Select Query កនុ្ Design View:. ............................................................................40 3.4. ការ Backup Database ទុក:.................................................................................................50 3.5. បប្កើត Delete Query:..........................................................................................................51 3.6. បប្កើត Update Query:.........................................................................................................53 3.7. បប្កើត Append Query:........................................................................................................55 3.8. បប្កើត Make-table Query:..................................................................................................57 3.9. បប្កើត Parameter Query:....................................................................................................60 3.10. បប្កើត Crosstab Query: ......................................................................................................62 3.11. Structure Query Language (SQL): .....................................................................................67
  • 2. Management Information System SETEC University II Table of Contents Chapter 4........................................................................................................................................... 71 Creating and Using Form.................................................................................................................. 71 4.1. បប្កើត Form បោយប្បើ Form tool:.................................................................................... 71 4.2. របបៀប View form:.............................................................................................................. 72 4.3. បប្កើត Form បោយប្បើ Split Form tool ............................................................................ 74 4.4. បប្កើត Form បោយប្បើ Multiple Items tool:..................................................................... 76 4.5. បប្កើត Form បោយប្បើ Wizard......................................................................................... 77 4.6. បប្កើត form បោយប្បើ Blank Form tool: .......................................................................... 79 4.7. ការរំកិល control បលើ form: ............................................................................................... 81 4.8. ការប្បើ្ាស់ form : .......................................................................................................... 82 4.9. បប្កើត Main form និ្ Subform......................................................................................... 83 4.10. Visual Basic for Application(VBA):.................................................................................. 89 4.11. Introduction to Variables: .................................................................................................. 92 4.12. Data Type:.......................................................................................................................... 93 4.13. Introduction to Procedures:.............................................................................................. 100 4.14. Conditional Statements .................................................................................................... 106 4.15. Counting and Looping Structures: ................................................................................... 107 4.16. Data Access Objects(DAO) ............................................................................................. 109 Chapter 5......................................................................................................................................... 114 Creating and Using Report.............................................................................................................. 114 5.1. បប្កើត Report បោយប្បើ Report tool: ............................................................................. 114 5.2. របបៀប View Report.......................................................................................................... 114 5.3. បប្កើត Report បោយប្បើ Report Wizard......................................................................... 117 5.4. បប្កើត Label បោយប្បើ Label Wizard ............................................................................ 121 5.5. បប្កើត Report បោយប្បើ Blank Report tool:................................................................... 124 5.6. អំពី Report Sections: ........................................................................................................ 125 5.7. បប្កើត Grouped Report ថ្មី បោយប្បើ Report Wizard:..................................................... 126 5.8. Homeworks ...................................................................................................................... 132
  • 3. SETEC University Management Information System Chapter 1: Introduction to MS-Access 2007 Page 1 of 140 Chapter 1 Introduction to MS-Access 2007 Introduction Microsoft Access 2007 Computer Application desktop computer computer network ។ ។ MS-Access 2007 ៖ - Table: (Store) - Query: Tables - Form: Table - Report: ជាដ ើម 1.1. MS-Access 2007: - ១ : Start  (All) Program  Microsoft Office  Microsoft Office Access 2007 ។ - ២ : Directory : C:Program FilesMicrosoft OfficeOffice12  File msaccess.exe Double Click ។ - ៣ : Start Run  Open: msaccess Enter OK ។
  • 4. Management Information System SETEC University Page 2 of 140 Chapter 1: Introduction to MS-Access 2007 MS-Access 2007 - Title bar: Office Button Quick Access Toolbar ។ - Office Button: Button (Save) Database ។ - Quick Access Toolbar: Icons Save, Undo Redo ។ Quick Access Toolbar Customized Button Icons ។ Office Button Quick Access Toolbar Customized Button Title bar
  • 5. SETEC University Management Information System Chapter 1: Introduction to MS-Access 2007 Page 3 of 140 - The Work Area: MS-Access 2007 : ១ : Template Categories: (Categori s (Template) ។ ២ : : - (New Blank Database) Database ។ - (Featured Online Templates): (Template) Database Microsoft ។ ៣ : Databases ។ 1.2. MS-Access 2007 - Office Button  Exit Access : Close Button Title bar : Alt + F4 1.3. Datab s - Office Button  New : ១ (Template Categories) Featuring  Blank Database - File Name: Database  Folder - Save as type Microsoft Access 2007 Database(*.accdb)  Create ។
  • 6. Management Information System SETEC University Page 4 of 140 Chapter 1: Introduction to MS-Access 2007 Program Window MS-Access 2007 - The Ribbon: Program Window Commands ។ - Navigation Pane: objects Database ។ - Tabbed Documents: Tables, Queries, Forms, Reports Macro Tab ។ View Button Ribbon Navigation Pane Tabbed Documents Status bar
  • 7. SETEC University Management Information System Chapter 1: Introduction to MS-Access 2007 Page 5 of 140 - Status bar: Program Window Buttons View ។ 1.4. Databas - Office Button  Open : ៣ (Open recent document): - Browse Database  Double-Click Database Open ។ ***End of Chaptert 1***
  • 8. Management Information System SETEC University Page 6 of 140 Chapter 2: Creating and Using Table Chapter 2 Creating and Using Table អ្វីដៅជា Table? Table object MS-Access ។ 2.1. T l 1. Database 2. Program Window : 3. Tabbed document, double-click Field/Column Headers : Right-click Field/Column Headers  Rename column 4. Column  Tab Field … Enter 5. Save Table  OK Field/Column Headers Row/Record Headers Tabbed document
  • 9. SETEC University Management Information System Chapter 2: Creating and Using Table Page 7 of 140 2.2. T l 1. Ribbon, Create  Icon: Table 2. Tabbed document, double-click Field/Column Headers : Right-click Field/Column Headers  Rename column 3. Column  Tab Field … Enter 4. Save Table  OK 2.3. T l Table Templates 1. Ribbon, Create  Icon: Table Templates Templates 2. Save Table  OK 2.4. Fi l olumn Table ១ : 1. Table Datasheet View 2. Right-click Field/Column Header Column 3. Insert Column ២ : 1. Field/Column Header Column 2. Ribbon, Datasheet  Fields & Column, Icon: Insert 2.5. Fi l olumn T l Field Templates 1. Table Datasheet View 2. Field/Column Header Column
  • 10. Management Information System SETEC University Page 8 of 140 Chapter 2: Creating and Using Table 3. Ribbon, Datasheet  Fields & Column, Icon: New Field 4. Field Templates, Fields Table ។ 2.6. Fi l olumn T l Datasheet View: 1. Table Datasheet View 2. Field/Column Header Column 3. Ribbon, Datasheet  Fields & Column, Icon: Add Existing Field 4. Field List, Fields Table 2.7. Fi l olumn T l Datasheet View ១ : 1. Table Datasheet View 2. Right-click Field/Column Header Field 3. Delete Column  YES ២ : 1. Table Datasheet View 2. Field/Column Header Field 3. Ribbon, Datasheet  Fields & Column, Icon: Delete  YES
  • 11. SETEC University Management Information System Chapter 2: Creating and Using Table Page 9 of 140 2.8. T l Design View 1. Ribbon, Create  Icon: Table Design 2. Field Name: Field Table 3. Data Type: user Field : - Text: ២៥៥ - Memo: ៦៣ ។ support Rich Text Formatting ។ E.g: Property: Text Format = Rich Text) - Number: - Date/Time: ១ - Currency:
  • 12. Management Information System SETEC University Page 10 of 140 Chapter 2: Creating and Using Table - AutoNumber: user record - Yes/No: user (Yes/No, True/False, or On/Off) - OLE Object: Object (Files) word, excel, graphics, sound - Hyperlink: Text (Path/URL) File, Web Page Website - Attachment: (attach) images, word, excel records Database - Lookup Wizard: Field user List Table List box Combo box 4. Description: Field Status bar 5. Field Properties: Fields
  • 13. SETEC University Management Information System Chapter 2: Creating and Using Table Page 11 of 140 Field Properties Data Type Data Type Field Properties Text - Field Size: user Field - Format: Datasheet View >: <: @[color]: E.g : @[red]/[black]/[blue]/[green]/[cyan]/[magenta]/[yellow]/[white] - Input Mask: : 0 (zero): + - 9 (nine): + - ។ # : + - ។ : Space user ។ L: A ? (Question mark): A A: a: &: sp C: sp <: >: - Caption: Label Column Heading Datasheet view Form - Validation Rule: Field - Validation Text: Text Message box user Validation Rule
  • 14. Management Information System SETEC University Page 12 of 140 Chapter 2: Creating and Using Table Data Type Field Properties - Required: - o Field - Yes: Field - Allow Zero Length: - No: String Null string - Yes: String Null string - Indexed: - No: The field is not indexed (default). index Field - Yes(Duplicates OK): index Field user - Yes(No Duplicates): index Field user Number - Field Size: - Byte: 1 byte of memory or disk space, holds from 0 to 255 - Integer: 2 bytes of storage, holds from -32,768 to 32,767 - Long Integer: 4 bytes of storage, holds from -2,147,483,648 to 2,147,483,647 - Single: 4 bytes of storage, holds from -3.402823x1038 to 3.402823x1038 - Double: 8 bytes of storage, holds from -1.79769313486232x10308 to 1.79769313486232x10308 - Format: - 000: to put 00 left number E.g.: 001 - #,##0.00R: format Riel E.g.: 10,000.00R Date/Time - Format: - d: Display the day of the month as one or two digits. - dd: Display the day of the month using two digits.
  • 15. SETEC University Management Information System Chapter 2: Creating and Using Table Page 13 of 140 Data Type Field Properties - ddd: Display the first three letters of the day of the week. - dddd: Display the full name of the day of the week. - m: Display the month of the year as one or two digits. - mm: Display the month of the year using two digits. - mmm: Use the first three characters of the month. - mmmm: Use the full name of the month. - yy: Use the last two digits of the year. - yyyy: Use the full year. - h: Display the hour using one or two digits. - hh: Display the hour using two digits. - n: Display the minute using one or two digits. - nn: Display the minute using two digits. - s: Display the second using one or two digits. - ss: Display the second using two digits. - Input Mask: - Date: 00/00/00 - Time: 00:00:00 E.g. 1 : Input mask Sample values (000) 000-0000 (206) 555-0248 (999) 999-9999 (206) 555-0248 ( ) 555-0248 (000) AAA-AAAA (206) 555-TELE #999 -20 2000 >L????L?000L0 GREENGR339M3, MAY R 452B7
  • 16. Management Information System SETEC University Page 14 of 140 Chapter 2: Creating and Using Table >L0L 0L0 T2F 8M4 00000-9999 98115- 98115-3007 >L<?????????????? Maria Brendan SSN 000-00-0000 SSN 555-55-5555 >LL00000-0000 DB51392-0493 E.g. 2: ValidationRule Property ValidationText Property <> 0 Entry must be a nonzero value. > 1000 Or Is Null Entry must be blank or greater than 1000. Lik “A????" Entry must be 5 characters and begin with the letter "A". 2.9. Primary Key: Primary Key Field (Records) Table ។  Field Primary Key: 1. Table Design View  Field Primary Key 2. Ribbon, Tab: Design  Icon: Primary Key  Primary Key Field: 1. Table Design View  Field Primary Key 2. Ribbon, Tab: Design  Icon: Primary Key 2.10.Import Table:  Import Table Database 1. Database Import Table
  • 17. SETEC University Management Information System Chapter 2: Creating and Using Table Page 15 of 140 2. Ribbon, t “Ext rn l D t ”  Import: Access Window : 3. Browse Database Tables 4. “Import T l s, qu ri s, forms, …”  OK Window :
  • 18. Management Information System SETEC University Page 16 of 140 Chapter 2: Creating and Using Table 5. “Import O j t”, tab: Tables  Tables Import  OK 6. “S v import st ps”  Close  Import Table File MS-Excel 1. Database Import Table 2. Ribbon, t “Ext rn l D t ”  Import: Excel Window :
  • 19. SETEC University Management Information System Chapter 2: Creating and Using Table Page 17 of 140 Browse File MS-Excel Tables 3. “Import th sour t …”  OK Window “Import Spr sh t Wiz r ” :
  • 20. Management Information System SETEC University Page 18 of 140 Chapter 2: Creating and Using Table 4. “Show Worksh ts” List sheet Import  Next window :
  • 21. SETEC University Management Information System Chapter 2: Creating and Using Table Page 19 of 140 5. “First Row ont ins olumn H ing” row ១ Column heading  Next window : 6. Field :  Field Name: Field  Data Type:  Indexed: Index  “Do not import fi l Skip ” Import Field 7. Next window :
  • 22. Management Information System SETEC University Page 20 of 140 Chapter 2: Creating and Using Table 8. :  Let Access add primary key: Access primary key  Choose my own primary key: Field primary key  No primary key: primary key 9. Next window :
  • 23. SETEC University Management Information System Chapter 2: Creating and Using Table Page 21 of 140 10. Table Import “Import to T l ”  Finish 11. Close 2.11. Export Tables  Export table File MS-Excel: 1. Navigation bar, table Export 2. Ribbon, t “Ext rn l D t ”  Export: Excel Window :
  • 24. Management Information System SETEC University Page 22 of 140 Chapter 2: Creating and Using Table 3. Browse Export table  options :  Export data with formatting and layout: Export format layout  Open the destination file after the export operation is complete: file export export  Export only the selected records: Export records 4. OK  Close 2.12. Table (Link Table):  Link Table Database : 1. Database Link table 2. Ribbon, tab: External Data  Import, Icon: Access Window :
  • 25. SETEC University Management Information System Chapter 2: Creating and Using Table Page 23 of 140 3. Browse Database Link tables 4. “Link to th t sour …”  OK Window : 5. “Link T l s”, Tables Link  OK
  • 26. Management Information System SETEC University Page 24 of 140 Chapter 2: Creating and Using Table 2.13. Lookup Wizard  Lookup Wizard : 1. table Design View 2. Data type: Lookup Wizard Field Lookup Wizard (E.g.: Sex) 3. win ow “Lookup Wiz r ” :
  • 27. SETEC University Management Information System Chapter 2: Creating and Using Table Page 25 of 140 4. “I will typ in th v lu s th t I w nt”  Next window :  Number of columns: columns 5. Col1, Lookup column (E.g.: 6. Next window : 7. lookup column  Finish 8. Save table
  • 28. Management Information System SETEC University Page 26 of 140 Chapter 2: Creating and Using Table  Lookup Wizard Tables/Queries : 1. table Design View 2. Data type: Lookup Wizard Field Lookup Wizard win ow “Lookup Wiz r ” : 3. “I w nt th lookup olumn to look up th v lu s in t l or qu ry”  Next
  • 29. SETEC University Management Information System Chapter 2: Creating and Using Table Page 27 of 140 4. table query Lookup column  Next 5. Fields “Av il l Fi l s” Field Lookup column  Next 6. sort order (Ascending/Descending) Fields  Next
  • 30. Management Information System SETEC University Page 28 of 140 Chapter 2: Creating and Using Table 7. column mouse (drag) column  “Hi k y olumn r omm n ” key column 8. Next 9. lookup column  Finish 10. + Yes: save table relationships + No: relationships
  • 31. SETEC University Management Information System Chapter 2: Creating and Using Table Page 29 of 140 11.Save table  lookup column Field 1. table Design View  Field lookup column 2. Field Properties, tab: Lookup  “Displ y ontrol”, Text Box 3. Save table
  • 32. Management Information System SETEC University Page 30 of 140 Chapter 2: Creating and Using Table 2.14. Relationships:  Relationships: 1. Ribbon, tab: Database Tools  Show/Hide, Icon: Relationships Relation tab : 2. tab: Design Icon: Show Tables : Right-click Relationship Window  Show Tables “Show T l ” :
  • 33. SETEC University Management Information System Chapter 2: Creating and Using Table Page 31 of 140 3. tab: Tables  tables relationship  Add 4. Close 5. Primary key (drag) Foreign key Edit Relationships :
  • 34. Management Information System SETEC University Page 32 of 140 Chapter 2: Creating and Using Table 6. Create 7. tab: Design Icon: Close Relationship tab  Relationship: 1. tab: Design Icon: Relationship 2. Double-click Relationship tie : Right-click Relationship tie  “E it R l tionship…” Relationship tie
  • 35. SETEC University Management Information System Chapter 2: Creating and Using Table Page 33 of 140 3. Relationship :  Enforce Referential Integrity: Relationship Tables ។  Cascade Update Related Fields: rim ry y Foreign Key ។  Cascade Delete Related Records: Primary table Foreign table ។ 4. OK  Relationship: 1. tab: Design Icon: Relationship 2. Relationship tie  key: Delete : Right-click Relationship tie  Delete 3. Yes 2.15. Password:  Password Database: 1. database Exclusive Mode:
  • 36. Management Information System SETEC University Page 34 of 140 Chapter 2: Creating and Using Table - Office Button  Open - Database Password  button: Open  “Op n Ex lusiv ”
  • 37. SETEC University Management Information System Chapter 2: Creating and Using Table Page 35 of 140 2. Ribbon, tab: Database Tools  Database Tools, Icon: Encrypt with Password 3. Password:  Password: Password  Verify: Password 4. OK  Password Database 1. database Exclusive Mode 2. Ribbon, tab: Database Tools  Database Tools, Icon: Decrypt Database 3. Password  OK
  • 38. Management Information System SETEC University Page 36 of 140 Chapter 3: Creating and Using Query Chapter 3 Creating and Using Query I. Query?: Query object MS-Access table tables ។ Query ។ Query Form, Report Data Access Page ។ Query MS-Access : 1. Select Query: u ry table ។ Select Query : Sum, Count, Average, Max in ។ 2. Action Query: Query t l s ។ Action Query ៤ : - Delete Query : table - Update Query : table ។ - Append Query : table table ។ - Make-table Query: table t l ។ 3. Parameter Query: Query ។ 4. Crosstab Query: Query ។ sum, average,
  • 39. SETEC University Management Information System Chapter 3: Creating and Using Query Page 37 of 140 ount,… ។ 5. Structured Query Language (SQL): query SQL Statement SQL Commands (SELECT, UPDATE DELETE) , SQL Clauses (WHERE ORDER ។ SQL relational databases Microsoft Access ។ II. Query: 3.1. S l t u ry wizard: 1. Ribbon, tab: Create  Other, Icon: Query Wizard Win ow “ w u ry” : 2. “Simpl u ry Wiz r ”  OK
  • 40. Management Information System SETEC University Page 38 of 140 Chapter 3: Creating and Using Query 3. “T l s u ri s”, Table  List “Av il l Fi l s”, Fields Query List “S l t Fi l s” 4. Next 5. “D t il shows v ry fi l of v ry r or ”  Next
  • 41. SETEC University Management Information System Chapter 3: Creating and Using Query Page 39 of 140 6. query  “Op n th qu ry to vi w inform tion”  Finish Lab 1: Create select query by using wizard: 1. t s “ orthwin . ” 2. Select Query table Products : ProductID, ProductName, UnitPrice, UnitsInStock. 3. Save query “qry ro u ts” Lab 2: Create select query by using wizard: (Modify the query design) 1. t s “ orthwin . ” 2. Select Query table Customers : CustomerID, ContactName, Address, City, Phone 3. S v th qu ry s “qry ustom r ont t” n hoos “ o ify th qu ry sign” 3.2. Run query: 1. Ribbon, Query Tools: Design  Result, Icon: Run
  • 42. Management Information System SETEC University Page 40 of 140 Chapter 3: Creating and Using Query 3.3. S l t u ry Design View:. 1. Ribbon, tab: Create  Other, Icon: Query Design Win ow “Show T l ” : 2. tab: Tables  Tables  Add  Close Query Window : 3. Double-click Field : mouse Field (drag) - Fi l table - T l tables
  • 43. SETEC University Management Information System Chapter 3: Creating and Using Query Page 41 of 140 - Sort (Ascending/Descending). - Show - Criteria: ។ : >, <, <=, >=, Is Null, Is Not Null, Between…An …, In, ot In, Lik , An , Or,<>,… ។ ** Like: (wildcards) : ១ E.g. Lik “sm ” ? E.g. Lik “sm?th” h r t r E.g. Lik “sm iy th” E.g. Lik “sm i th” - E.g. Lik “ - ” * Disable the output of all fields in query design: - Office Button  Access Options Object Designer  “ u ry D sign”, uncheck  Output all fields
  • 44. Management Information System SETEC University Page 42 of 140 Chapter 3: Creating and Using Query Lab: Select Query Design View: 1. database: Northwind.accdb 2. Select Query table: Customers : a. (Sort: Ascen ing CompanyName ។ b. London c. Fr ។ 3. Select query table Products : a. ៥ ។ b. ៣ t goryID=8 S foo ។ c. Chang Unit ri $18.00 ។ 4. Select query table Orders : a. 12/11/1996 20/04/1997 ShipCountry=Germany ។ b. (ShipRegion) WA, CA, SP ។ c. (ShipRegion) ។ 5. Select query t l ustom rs Orders ។ Homework 1. ProductName, UnitPrice CategoryName (Categories) Seafood ។ 2. ProductName, UnitPrice CategoryName ១ (Categories) Seafood ។ 3. CategoryID, ProductName, UnitPrice UnitsInStock “r” ៣ E.g: Norwood, Carnarvon, Sir Ro n y, … ។
  • 45. SETEC University Management Information System Chapter 3: Creating and Using Query Page 43 of 140 E.g: > 234 Returns all numbers greater than 234. To find all numbers less than 234, use < 234. >= "Cajhen" Returns all records from Cajhen through the end of the alphabet Between #2/2/2007# And #12/1/2007# Returns dates from 2-Feb-2007 through 1-Dec-2007 (ANSI-89). If your database uses the ANSI-92 wildcard characters, use single quotation marks (') instead of pound signs (#). Example: Between '2/2/2007' And '12/1/2007' Not "Germany" Finds all records where the exact contents of the field are not exactly equal to "Germany." The criterion will return records that contain characters in addition to "Germany," such as "Germany (euro)" or "Europe (Germany)". Not "T*" Finds all records except those beginning with T. If your database uses the ANSI-92 wildcard character set, use the percent sign (%) instead of the asterisk (*). Not "*t" Finds all records that do not end with t. If your database uses the ANSI-92 wildcard character set, use the percent sign (%) instead of the asterisk (*). In(Canada,UK) In a list, finds all records containing Canada or UK. Like "[A-D]*" In a Text field, finds all records that start with the letters A through D. If your database uses the ANSI-92 wildcard character set, use the percent sign (%) instead of the asterisk (*). Like "*ar*" Finds all records that include the letter sequence "ar". If your database uses the ANSI-92 wildcard character set, use the percent sign (%) instead of the asterisk (*).
  • 46. Management Information System SETEC University Page 44 of 140 Chapter 3: Creating and Using Query Lik “ ison Dewe?" Finds all records that begin with "Maison" and contain a 5-letter second string in which the first 4 letters are "Dewe" and the last letter is unknown. If your database uses the ANSI-92 wildcard character set, use the underscore (_) instead of the question mark (?). #2/2/2007# Finds all records for February 2, 2007. If your database uses the ANSI-92 wildcard character set, surround the date with single quotation marks instead of pound signs ('2/2/2007'). < Date() - 30 Uses the Date function to return all dates more than 30 days old. Date() Uses the Date function to return all records containing today's date. Between Date() And D t A “ ", 3, Date()) Uses the Date and the DateAdd functions to return all records between today's date and three months from today's date. Is Null Returns all records that contain a null (blank or undefined) value. Is Not Null Returns all records that contain any value (that are not null). “" Returns all records that contain a zero-length string. You use zero- length strings when you need to add a value to a required field, but you don't yet know what the actual value is. For example, a field might require a fax number, but some of your customers might not have fax machines. In that case, instead of entering a number, you enter a pair of double quotation marks with no space between them “" . 3.3.1. Alias field name: Field query : NewFieldName : OldFieldName E.g 1. : Name : FirstName
  • 47. SETEC University Management Information System Chapter 3: Creating and Using Query Page 45 of 140 E.g 2. Full m First m & “ “ & L st m E.g 3. : Sub Total : [UnitPrice]*[Quantity] 3.3.2. Aggregate function: 1. Select Query Design View 2. Ribbon, Query Tools: Design 3. Show/Hide, Icon: Total Total grid : 4. Total grid, Aggregate function fields : Group y, Sum, ount, Avg, x, in, … Total grid
  • 48. Management Information System SETEC University Page 46 of 140 Chapter 3: Creating and Using Query 5. Run 3.3.3. Expression Builder: 1. Select Query Design View 2. Field 3. Ribbon, Query Tools: Design  Query Setup, Icon: Builder : Right-click Field  Builder
  • 49. SETEC University Management Information System Chapter 3: Creating and Using Query Page 47 of 140 4. Double-Click folder: Function  Built-In Function  functions Double-click function 5.  OK 6. Run query Lab1: Select Query Aggregate function 1. database Northwind.accdb 2. Select Query table Products a. Group by CategoryID b. Sum on UnitsInStock 3. Save query “qryUnitsInSto k y t gory” 4. Run the query Lab2: Calculation using Expression Builder 1. database Northwind.accdb 2. Select Query table OrderDetails fields: OrderID, ProductID, UnitPrice, Quantity 3. field : - SubTotal Before Discount: [UnitPrice]*[Quantity] - Discount Price: [UnitPrice]*[Quantity]*Discount function function
  • 50. Management Information System SETEC University Page 48 of 140 Chapter 3: Creating and Using Query - SubTotal After Discount: [SubTotal Before Discount] – [Discount Price] : SubTotal After Discount: [UnitPrice]*[Quantity]*(1-[Discount]) : SubTotal After Discount$: Format([UnitPrice]*[Quantity]*(1- Dis ount ,” urr n y” 4. S v qu ry s “qrySu Tot l” 3.3.4. Build-in Function - IIF: Function ។ : IIf(expression, truepart, falsepart) expression: truepart: falsepart: E.g.1 R sult IIf S or >=50,” ss ”,”F il ” E.g.2 : Mention: IIf([TotalScore] Between 450 And 500,"Excellent",IIf([TotalScore] Between 350 And 449,"Very Good",IIf([TotalScore] Between 200 And 349,"Good","Poor"))) E.g. 3 L ngu g IIf ountryR gion =“It ly”, “It li n", “Som oth r l ngu g " E.g. 4: Status: IIf([Due Date]<Date(),“OVERDUE",IIf([Due Date]=Date(),“Due",“Not Yet Due")) Lab 1: Build-in function IIF 1. database Northwind.accdb 2. Select Query table Products : ProductID, ProductName, UnitInStock 3. field StockStatus UnitsInStock=0 “ ro u t out of sto k” “ ro u t not out of sto k” 4. Save query “qrySto kSt tus”
  • 51. SETEC University Management Information System Chapter 3: Creating and Using Query Page 49 of 140 Lab: nested function IIF 1. database Northwind.accdb 2. Select Query table Products : ProductID, ProductName, UnitsInStock, UnitPrice 3. field Mention UnitPrice 1 - 20 ntion “V ry h p” UnitPrice 21 - 50 ntion “ h p” UnitPrice 51 - 70 ntion “Exp nsiv ” UnitPrice > 70 ntion “V ry Exp nsiv ” 4. Save query “qry ro u t ntion” 3.3.5. Build-In-Function : Abs(Number): Absolute value Avg(expr): Average CBool(expr): Convert to Boolean CByte(expr): Convert to byte CCur(expr): Convert to currency CDate(date): Convert to date CDbl(expr): Convert to double CInt(expr): Convert to integer CLng(expr): Convert to long integer Chr(charcode): Convert ascii to character Asc(Strexpr): Convert character to ascii Date(): Display current date DateAdd(Interval,Number,Date): Add to date by interval DateDiff(Interval,Date1,Date2): Date2 minus Date1 by interval DatePart(Interval,Date): Select date by interval * Interval : Year yy, yyyy Quarter q, q Month mm, m
  • 52. Management Information System SETEC University Page 50 of 140 Chapter 3: Creating and Using Query * Interval : Day dd, d Week wk, ww Hour hh Minute mi, n Second ss, s Milisecond ms Ex D t rt “yyyy”,D t * Build-in functions - Date/Time - DateAdd(Interval,Number,Date): interval E.g. : D t A “yyyy”,10, Hir D t - DateDiff(Interval,Date1,Date2): Date2 Date1 interval E.g. : D t Diff “yyyy”, irthD t , ow - DatePart(Interval,Date): interval E.g. : D t rt “ ”, irthD t D t rt “m”, irthD t D t rt “yyyy”, irthD t * Build-in functions - Format() E.g. : Form t irthD t , “yyyy” Form t Amount , “ urr n y” Format([Amount], “៛ #,##0.00") 10 Year Aniversary: Format(DateAdd("m",10,[HireDate]),"dd/mmm/yy") 3.4. kup D t s : 1. Database file Back up 2. Office button  Manage  Back Up Database
  • 53. SETEC University Management Information System Chapter 3: Creating and Using Query Page 51 of 140 3. Save As dialog box, browse Database file 4. File name, Database file Back up 5. Save 3.5. Delete Query: table ។ 1. S l t u ry Design View 2. Ribbon, Query Tools: Design 3. Query Type, Icon: Delete Delete grid :
  • 54. Management Information System SETEC University Page 52 of 140 Chapter 3: Creating and Using Query 4. field record: - Field: field - Table: table - Delete: + From: field table record + Where: field 5. Run the query Delete grid
  • 55. SETEC University Management Information System Chapter 3: Creating and Using Query Page 53 of 140 6. Yes records L D l t u ry : 1. records table: Order Details (UnitsInStock) 30 ។ 2. table: Orders OrderID 10500 ។ 3. table: Orders ID = “ LAUS” ។ 4. table: Products (CategoryName) Seafood ។ 3.6. Update Query: table ។ 1. S l t u ry Design View 2. Ribbon, Query Tools: Design 3. Query Type, Icon: Update Update grid
  • 56. Management Information System SETEC University Page 54 of 140 Chapter 3: Creating and Using Query 4. fields fields Update record - Field: field Update record - Table: table - Update To: - Criteria: 5. Run the query Update grid
  • 57. SETEC University Management Information System Chapter 3: Creating and Using Query Page 55 of 140 6. Yes Lab: Update query 1. Country=“ xi o” “ m o i ” table: Customers 2. Update Unit ri t l ro u ts ១ stock ២ ។ 3.7. Append Query: record table ។ 1. S l t u ry Design View Source table 2. Ribbon, Query Tools: Design 3. Query Type, Icon: Append 4. : - T l m Destination table record - Current Database: Database - Anoth r D t s record table database
  • 58. Management Information System SETEC University Page 56 of 140 Chapter 3: Creating and Using Query 5. OK  fields fields Append - Field: Field Source table - Table: Source table - Append To: Field Destination table - Criteria: 6. Run the query 7. Yes
  • 59. SETEC University Management Information System Chapter 3: Creating and Using Query Page 57 of 140 L r t App n u ry : 1. table Clients table: Customers 2. table Customers ountry=” xi o” table Clients ។ 3. table Customers fax table Clients ។ 4. table Customers Germany table Clients ។ 5. table Customers Canada UK table Clients ។ E.g.: < Date() - 30 Returns all dates more than 30 days old. Betw n D t An D t A “ ", 3, D t Returns ll r or s tw n to y‘s date and three months from today‘s date. 3.8. Make-table Query: table t l ។ 1. S l t u ry Design View tables 2. Ribbon, Query Tools: Design 3. Query Type, Icon: Make-table Query : 4. : - T l m table record
  • 60. Management Information System SETEC University Page 58 of 140 Chapter 3: Creating and Using Query - Current Datab s table Database - Anoth r D t s table database 5. OK 6. fields fields table 7. Run the query 8. Yes
  • 61. SETEC University Management Information System Chapter 3: Creating and Using Query Page 59 of 140 Lab: Make-table query : 1. database Northwind.accdb 2. t l CustomerAG fields: CustomerID, ContactName, Address ity table: Customers ID A G ។ 3. t l ustom rLon on ri fields: CustomerID, ContactName, Address ity table: Customers London Madrid ។ 4. t l ro u t otSE fields: ProductID, ProductName, UnitPrice UnitsInStock table: Products “s” “ ” ។
  • 62. Management Information System SETEC University Page 60 of 140 Chapter 3: Creating and Using Query 3.9. Parameter Query: Query ។ 1. S l t u ry Design View tables 2. fields field Parameter Query 3. Parameter Query Criteria field E.g: Between [Start Date] And [End Date] 4. Run the query Parameter
  • 63. SETEC University Management Information System Chapter 3: Creating and Using Query Page 61 of 140 Lab: Create Parameter query 1. query table: Orders (OderDate) (Begin Date End Date) ។ 2. query table: Products stock ។ 3. query table: Customers (CompanyName) ។ 4. query table: Customers omp ny m ។
  • 64. Management Information System SETEC University Page 62 of 140 Chapter 3: Creating and Using Query 3.10. Crosstab Query: Query ។ 1. Ribbon, tab: Create  Other, Icon: Query Wizard Win ow “ w u ry” : 2. “ rosst u ry Wiz r ”  OK Column Heading Row Heading
  • 65. SETEC University Management Information System Chapter 3: Creating and Using Query Page 63 of 140 3. table query Crosstab Query  Next 4. field Row Heading  Next
  • 66. Management Information System SETEC University Page 64 of 140 Chapter 3: Creating and Using Query 5. field Column Heading  Next 6. interval field Date/Time
  • 67. SETEC University Management Information System Chapter 3: Creating and Using Query Page 65 of 140 7. field function field  Next 8. query  Finish
  • 68. Management Information System SETEC University Page 66 of 140 Chapter 3: Creating and Using Query Lab: Crosstab query: 1. database Northwind.accdb 2. crosstab query table Customers customers ountry (City) ។ 3. crosstab query table Orders ។ 4. Wizard, crosstab query table: Orders Shippers (Freight) (ShipCountry) (CompanyName) ។
  • 69. SETEC University Management Information System Chapter 3: Creating and Using Query Page 67 of 140 3.11. Structure Query Language (SQL): query SQL Statement SQL Commands (SELECT, UPDATE DELETE), SQL CLAUSES (WHERE ORDER ។ SQL relational databases Microsoft Access ។ a) SQL: 1. Ribbon, tab: Create 2. Other, Icon: Query Design 3. Show Table, Close 4. Query Tools: Design  Result, Icon: SQL
  • 70. Management Information System SETEC University Page 68 of 140 Chapter 3: Creating and Using Query b) Run SQL: - Ribbon, Query Tools: Design  Result, Icon: Run c) View SQL: - Ribbon, tab: Home  View  SQL View *** SELECT Statement Instructs the Microsoft Jet database engine to return information from the database as a set of records. Syntax : SELECT [predicate] { * | table.* | [table.]field1 [AS alias1] [, [table.]field2 [AS alias2] [, ...]]} FROM tableexpression [, ...] [IN externaldatabase] [WHERE... ] [GROUP BY... ] [HAVING... ] [ORDER BY... ] [WITH OWNERACCESS OPTION]
  • 71. SETEC University Management Information System Chapter 3: Creating and Using Query Page 69 of 140 The SELECT statement has these parts: Part Description Predicate One of the following predicates: ALL, DISTINCT, DISTINCTROW, or TOP. You use the predicate to restrict the number of records returned. If none is specified, the default is ALL. * Specifies that all fields from the specified table or tables are selected. Table The name of the table containing the fields from which records are selected. field1, field2 The names of the fields containing the data you want to retrieve. If you include more than one field, they are retrieved in the order listed. alias1, alias2 The names to use as column headers instead of the original column names in table. tableexpression The name of the table or tables containing the data you want to retrieve. externaldatabase The name of the database containing the tables in tableexpression if they are not in the current database. Lab: queries SQL Statement: 1. database Northwind.accdb 2. SQL : a. ustom rID, ont t m A r ss t l ustom rs ។ b. ProductID, ProductName, UnitPrice UnitsInStock ១ UnitsInStock table: Products ។ c. ro u t m , Unit ri UnitsInSto k table: Products stock ៥ (UnitPrice) ២ ។ d. Or rID, Or rD t , Fr ight Ship m table: Orders (Freight) ៣ ៤ ។ e. L st m First m table: Employees sort Descending LastName ។
  • 72. Management Information System SETEC University Page 70 of 140 Chapter 3: Creating and Using Query f. ២ table: [Order Details] ។ g. t l Or rs ។ h. OrderID, ១ Group by: OrderID t l Or r D t ils ។ i. Sort: Ascending CompanyName ។ j. ustom rID, ont t m omp ny m Subquery ។ k. ContactName, Address Country table: Customers, order by Country, ContactName ។ *****End of Chapter 3*****
  • 73. SETEC University Management Information System Chapter 4: Creating and Using Form Page 71 of 140 Chapter 4 Creating and Using Form អ្វីដៅជា Form? Form Object MS-Access interface table query ។ 4.1. Form Form tool: 1. Navigation Pane, table query Form 2. Ribbon, tab: Create  Form, icon: Form 3. Access form Layout view :
  • 74. Management Information System SETEC University Page 72 of 140 Chapter 4: Creating and Using Form 4. Save save form 5. OK 4.2. View form: 1. Navigation Pane, Double-click form form view Form View:
  • 75. SETEC University Management Information System Chapter 4: Creating and Using Form Page 73 of 140 2. Ribbon, tab: Home  Views, icon: View : icons Status bar - Form View: user ។
  • 76. Management Information System SETEC University Page 74 of 140 Chapter 4: Creating and Using Form - Layout View: form (formatting) ។ - Design View: form (formatting) Layout View ។ 4.3. Form Split Form tool 1. Navigation Pane, table query Form
  • 77. SETEC University Management Information System Chapter 4: Creating and Using Form Page 75 of 140 2. Ribbon, tab: Create  Forms, icon: Split Form 3. Access form Layout View : Form View Datasheet View
  • 78. Management Information System SETEC University Page 76 of 140 Chapter 4: Creating and Using Form 4.4. Form Multiple Items tool: 1. Navigation Pane, table query Form 2. Ribbon, tab: Create  Form, icon: Multiple Items 3. Access form Layout View :
  • 79. SETEC University Management Information System Chapter 4: Creating and Using Form Page 77 of 140 4.5. Form Wizard 1. Ribbon, tab: Create  Form, More Forms  Form Wizard 2. Wizard : 3. “T l s u ri s” , t l query 4. List “Av il l Fi l s”, fi l s form  Next
  • 80. Management Information System SETEC University Page 78 of 140 Chapter 4: Creating and Using Form 5. layout form olumn r, T ul r, D t sh t, …  Next 6. style form Access 2003, Access 2007, Apex, ...  Next
  • 81. SETEC University Management Information System Chapter 4: Creating and Using Form Page 79 of 140 7. form title bar  “Op n th form to vi w or nt r information.” Finish 4.6. form Blank Form tool: 1. Ribbon, Create  Forms, icon: Blank Form 2. Layout View Field List pane :
  • 82. Management Information System SETEC University Page 80 of 140 Chapter 4: Creating and Using Form 3. Field List pane, (+) table fields table 4. Double-click field form ។ fields key: Ctrl + fields ។ 5. tools Control tab: Format Logo, , form
  • 83. SETEC University Management Information System Chapter 4: Creating and Using Form Page 81 of 140 6. control form: - Design view Right-click form  Design View - Ribbon, tab: Design  tools Controls 4.7. control form: 1. form Design View  control 2. Right-click control  Layout  Remove 3. Mouse pointer Controls
  • 84. Management Information System SETEC University Page 82 of 140 Chapter 4: Creating and Using Form 4. Control Mouse pointer Controls 4.8. form : Cursor field field - Tab: Cursor field - Shift + Tab: Cursor - Ctrl + Home: Cursor record ១ Form - Ctrl + End: Cursor record Form
  • 85. SETEC University Management Information System Chapter 4: Creating and Using Form Page 83 of 140 4.9. Main form Subform Main form Subform tables One-to-Many ។ Main form table One Subform table Many ។ Main form Columnar Form Subform Tabular Form Datasheet Form  form Subform Form Wizard 1. Ribbon, tab: Create  Forms, icon: More Forms  Form Wizard 2. window Form Wizard : 3. Tables/Queries, table/query Main form 4. Double-click fields Main form 5. Wizard Tables/Queries, table/query Subform 6. Double-click fields Subform
  • 86. Management Information System SETEC University Page 84 of 140 Chapter 4: Creating and Using Form 7. Next 8.  “Form with su form s ” 9. Next
  • 87. SETEC University Management Information System Chapter 4: Creating and Using Form Page 85 of 140 10. layout subform : Tabular Datasheet 11. Next 12. style  Next
  • 88. Management Information System SETEC University Page 86 of 140 Chapter 4: Creating and Using Form 13. Main form Subform  “Op n th form to vi w or nt r inform tion” 14. Finish  Subform form 1. Main form Columnar
  • 89. SETEC University Management Information System Chapter 4: Creating and Using Form Page 87 of 140 2. Subform Tabular Form Datasheet Form 3. View main form Design View 4. Ribbon, tab: Design  Controls, icon: Use Control Wizards 5. Navigation Pane, Subform Detail Main form design
  • 90. Management Information System SETEC University Page 88 of 140 Chapter 4: Creating and Using Form 6. Access Subform Main form Relationship Database ។ *** Access Subform Main form : 1. Navigation Pane, Right-click Main form  Design 2. form design, Subform 3. Ribbon, tab: Design Form Design Tools  Tools, icon: Property Sheet 4. Property Sheet, tab: Data Properties - Source Object: form Subform
  • 91. SETEC University Management Information System Chapter 4: Creating and Using Form Page 89 of 140 - Linked Master Field: Field (Primary key) Main form Subform - Linked Child Field: Field (Foreign key) Subform Main form 5. View form Form View Lab: Create Main form and Subform 1. Main form table: Customers 2. Subform table: Orders 3. Subform Main form 4.10. Visual Basic for Application(VBA): V A Microsoft Visual Basic code Windows Application Microsoft ។ a. What is Object? Object … ។ MS-Access Form, Object Control
  • 92. Management Information System SETEC University Page 90 of 140 Chapter 4: Creating and Using Form - Text Box : Control keyboard - Label : Control Control - Command Button : Control button event - h k ox Control check uncheck - Option Button : Control ន ។ a.1. What is Property? Property Object Control Form MS- Access ។ rop rti s ontrols form .Left : form .Top : form .Height: Control .Width: Control a.2. What is Method? Method object ។ ObjectName.MethodName E.g. : txtFirstName.SetFocus Me!txtLastName.Undo rs.MoveNext rs.MoveFirst a.3. What is Event? Event (Procedure) user program code ។ E.g.: Private Sub btnOK_Click() Statements… End Sub
  • 93. SETEC University Management Information System Chapter 4: Creating and Using Form Page 91 of 140 Private Sub Form_Load() Statements… End Sub Private Sub txtFirstName_GotFocus() Statements… End Sub b. form Design view Ribbon, Tab: Create  Form Design c. Code vi w o form View form Design View  Form Design Tools, Tab: Design  View Code d. event control Click control  Property windows, tab: Event  event button : Right-click control  uil Ev nt… Code Builder  OK Lab: Form Code 1. Form 2. Code Editor, code Private Sub btnOK_Click() txtFirstName.Value = "Sabay" txtLastName.Value = "Sok" txtAddress.Value = "Bokor mountain" End Sub Private Sub btnClear_Click() txtFirstName.Value = "" txtLastName.Value = "" txtAddress.Value = "" txtFirstName.SetFocus End Sub txtFirstName txtLastName txtAddress btnOK btnClear
  • 94. Management Information System SETEC University Page 92 of 140 Chapter 4: Creating and Using Form 4.11. Introduction to Variables: Variable memory application ។ variable memory ។ E.g.1: Private Sub Detail_Click() SomeColor = vbRed Detail.BackColor = SomeColor End Sub - (declare) variable Dim variable ។ Dim VariableName E.g.: Private Sub Form_Load() Dim thisVar thisVar = 15 MsgBox thisVar End Sub - Option Explicit: variable (Error) ។ E.g.: Private Sub Form_Load() Dim thisVar thisVar = 15 MsgBox thisInt '<-- Note the misspelled "thisInt" End Sub Option Explicit Code Builder variable variable ។ E.g. : Option Explicit Private Sub Form_Load() ..... End Sub
  • 95. SETEC University Management Information System Chapter 4: Creating and Using Form Page 93 of 140 - Option Explicit Code Builder: 1. menu Microsoft Visual Basic, Tools  Option… 2. tab: Editor  Code Settings, check h k ox “ R quir V ri l D l r tion” 4.12. Data Type: Data Type variable ។ Dim VariableName As DataType Or: Dim VariableName1 As DataType1, VariableName2 As DataType2 Dim VariableName3 As DataType3 E.g. : Dim StudentName As Byte Dim CountryName As String - : Data Type Description (Range) Byte 1-byte binary data (0 to 255) Integer 2-byte integer (– 32,768 to 32,767) Long 4-byte integer (– 2,147,483,648 to 2,147,483,647) Single 4-byte floating- point number (– 3.402823E38 to – 1.401298E – 45 (negative values)) 1.401298E – 45 to 3.402823E38 (positive values) Double 8-byte floating- point number (– 1.79769313486231E308 to – 4.94065645841247E – 324 (negative values)) 4.94065645841247E – 324 to 1.79769313486231E308 (positive values) Currency 8-byte number with fixed decimal point (– 922,337,203,685,477.5808 to 922,337,203,685,477.5807) String String of characters (Zero to approximately two billion characters) Date 8-byte date/time value (January 1, 100 to December 31, 9999) - variable (Prefix) variable
  • 96. Management Information System SETEC University Page 94 of 140 Chapter 4: Creating and Using Form Data Type Prefix Example Boolean bln blnFound Byte byt bytTracks Date/Time dtm dteStartOfShift Double dbl dblDistance Error err errCantOpen Integer int intNbrOfStudents Long lng lngPopulation Object obj objConnection Single sng sngAge String str strCountryName Currency cur curHourlySalary Variant var varFullName - Functions CBool(): convert Boolean CStr(): convert String CByte(): convert Byte (Small number) Int convert Integer Lng convert Long CSng convert Single CDbl: convert Double ur convert Currency D t convert Date - Constant: variable ។ Const VariableName = Value E.g. : Const conPI = 3.14159265359 vbCrLf (Carriage Return-Line Feed Constant) : constant text ។ - Static keyword variable function sub procedure ។ variable keyword: Static memory function sub procedure ។
  • 97. SETEC University Management Information System Chapter 4: Creating and Using Form Page 95 of 140 E.g. : Sub Calculate() Static intVar As Integer intVar = intVar + 1 MsgBox intVar End Sub Private Sub btnCalculate_Click() Call Calculate End Sub Lab: Data Type: 1. form Design View 2. form  Property windows, tab: Event  event “On li k” button 3. code Private Sub Detail_Click() Dim strName As String,intYearBorn As Integer Dim intAge As Integer strName = InputBox("Your name: ") intYearBorn = InputBox("Year borned: ") intAge = Format(Now(), "yyyy") - intYearBorn MsgBox "Hello " & strName & vbCrLf & _ "you are " & intAge & " years old." End Sub 4. form Design View A ontrol omm n utton : - Caption: Calculate - Name: btnCalculate 5. code Sub Calculate() Static intVar As Integer intVar = intVar + 1 MsgBox intVar End Sub - event: On Click button: Calculate code: Private Sub btnCalculate_Click() Call Calculate End Sub 6. Save form “frmSt ti V ri l ”
  • 98. Management Information System SETEC University Page 96 of 140 Chapter 4: Creating and Using Form *** MsgBox function: (See help: MsgBox Function) message dialog box click button user constant button user click ។ MsgBox(prompt[, buttons Or icon] [, title]) - prompt: string expression message dialog box ។ - button: buttons prompt Constant Value Description vbOKOnly 0 Display OK button only. vbOKCancel 1 Display OK and Cancel buttons. vbAbortRetryIgnore 2 Display Abort, Retry, and Ignore buttons. vbYesNoCancel 3 Display Yes, No, and Cancel buttons. vbYesNo 4 Display Yes and No buttons. vbRetryCancel 5 Display Retry and Cancel buttons. vbCritical 16 Display Critical Message icon. vbQuestion 32 Display Warning Query icon. vbExclamation 48 Display Warning Message icon. vbInformation 64 Display Information Message icon. vbDefaultButton1 0 First button is default. vbDefaultButton2 256 Second button is default. vbDefaultButton3 512 Third button is default. vbDefaultButton4 768 Fourth button is default. Constants VBA constants code ។ icon title prompt buttons
  • 99. SETEC University Management Information System Chapter 4: Creating and Using Form Page 97 of 140 If the user click The function returns Numeric Value vbOK 1 vbCancel 2 vbAbort 3 vbRetry 4 vbIgnore 5 vbYes 6 vbNo 7 - titl string Title bar Message Box ។ E.g. : Private Sub Detail_Click() MsgBox "Do you really want to delete this record?", _ vbYesNoCancel Or vbQuestion, "Confirmation" End Sub - buttons MsgBox Dim x As Integer x = MsgBox("Do you really want to delete this record?", _ vbYesNoCancel + vbQuestion, "Confirmation") code MsgBox buttons Yes, No Cancel ។ button: Yes constant vbYes=6 x ។ *** InputBox Function: message dialog box text click button user string text box ។ InputBox(prompt[, title] [, default])
  • 100. Management Information System SETEC University Page 98 of 140 Chapter 4: Creating and Using Form - prompt title: Message Box ។ - f ult text text box user ។ E.g. : Private Sub Form_Load() Dim x As Integer, y As Integer Dim sum As Integer x = InputBox("Please enter value of x", "Enter value of x") y = InputBox("Please enter value of y", "Enter value of y") sum = x + y MsgBox "The sum of " & x & " and " & y & " is " & sum, ,"Result" End Sub
  • 101. SETEC University Management Information System Chapter 4: Creating and Using Form Page 99 of 140 Lab : Form Code: 1. form - Add buttons properties Name Caption Events btnSum Sum On_Click btnSubtract Subtract On_Click btnMultiply Multiply On_Click btnDivide Divide On_Click - click buttons , access InputBox user (x y) ។ 2. code Option Compare Database Option Explicit Private Sub btnDivide_Click() Dim x As Integer, y As Integer Dim divide As Integer x = InputBox("Please enter value of x", "Enter value of x") y = InputBox("Please enter value of y", "Enter value of y") divide = x / y MsgBox "The division of " & x & " and " & y & " is " & _ divide, , "Result" End Sub Private Sub btnMutiply_Click() Dim x As Integer, y As Integer Dim multiply As Integer x = InputBox("Please enter value of x", "Enter value of x") y = InputBox("Please enter value of y", "Enter value of y") multiply = x * y MsgBox "The multiplication of " & x & " and " & y & " is " & multiply, , "Result" End Sub
  • 102. Management Information System SETEC University Page 100 of 140 Chapter 4: Creating and Using Form Private Sub btnSubtract_Click() Dim x As Integer, y As Integer Dim subtract As Integer x = InputBox("Please enter value of x", "Enter value of x") y = InputBox("Please enter value of y", "Enter value of y") subtract = x - y MsgBox "The subtract of " & x & " and " & y & " is " & subtract, , "Result" End Sub Private Sub btnSum_Click() Dim x As Integer, y As Integer Dim sum As Integer x = InputBox("Please enter value of x", "Enter value of x") y = InputBox("Please enter value of y", "Enter value of y") sum = x + y MsgBox "The sum of " & x & " and " & y & " is " & sum, , "Result" End Sub 4.13. Introduction to Procedures: Procedure code program ។ ro ur s VBA Sub Procedure Function Procedure ។ procedures Function Procedure return Sub Procedure return (Call) ។ 4.13.1. Sub Procedure: Sub ProcedureName([Arguments]) Statements… End Sub E.g. : Sub Multiply() Dim x As Integer, y As Integer Dim result As Integer x = txtValue1 y = txtValue2 result = x * y txtResult = result End Sub - (Call) Sub Procedure Call ProcedureName([Arguments]) ProcedureName [Arguments]
  • 103. SETEC University Management Information System Chapter 4: Creating and Using Form Page 101 of 140 E.g. : Private Sub btnCalculate_Click() Call Multiply End Sub - Sub Procedure Arguments Sub Multiply(x As Integer, y As Integer) Dim result As Integer result = x * y txtResult = result End Sub Private Sub btnCalculate_Click() Call Multiply(txtValue1, txtValue2) End Sub 4.13.2. Function Procedure: Function FuntionName([Arguments]) As DataType Statements… End Function - Function Procedure Sub Procedure return As DataType return ។ E.g. : Function Divide() As Integer Dim x As Integer, y As Integer x = txtValue1 y = txtValue2 Divide = x / y End Function - Function Procedure ។ statements Sub Procedure Sub Procedure ។ return text box variable ។ E.g. : Private Sub btnCalculate_Click() txtResult = Divide End Sub
  • 104. Management Information System SETEC University Page 102 of 140 Chapter 4: Creating and Using Form Lab: Sub Procedure: 1. form 2. Sub Procedure 3. Sub Procedure 4. click button: Calculate ។ 5. click button: New clear text box ។ Sub SquareSolution() Dim dblSide As Double Dim dblPerimeter, dblArea As Double dblSide = txtSide dblPerimeter = dblSide * 4 dblArea = dblSide * dblSide txtSqPerimeter = dblPerimeter txtSqArea = dblArea End Sub Private Sub RectangleSolution() Dim dblLength, dblHeight As Double Dim dblPerimeter, dblArea As Double dblLength = txtLength dblHeight = txtHeight dblPerimeter = (dblLength + dblHeight) * 2 dblArea = dblLength * dblHeight txtRecPerimeter = dblPerimeter txtRecArea = dblArea End Sub
  • 105. SETEC University Management Information System Chapter 4: Creating and Using Form Page 103 of 140 Private Sub btnCalculateRec_Click() RectangleSolution End Sub Private Sub btnCalculateSqare_Click() Call SquareSolution End Sub Private Sub btnSqNew_Click() txtSide = "" txtSqPerimeter = "" txtSqArea = "" txtSide.SetFocus End Sub Private Sub btnRecNew_Click() txtLength = "" txtHeight = "" txtRecPerimeter = "" txtRecArea = "" txtLength.SetFocus End Sub Homework: Function Procedure: Lab Function Procedure ។ 4.13.3. Procedure Arguments: - Sub ProcedureName(Var1 As Datatype, Var2 As Datatype,…) Statements End Sub Function FunctionName(Var1 As Datatype, Var2 As Datatype,…) _ As Datatype Statements End Function E.g. 1 Function Procedure ។ Function CubeArea(Side As Double) As Double CubeArea = Side * Side * 6 End Function Function CubeVolume(Side As Double) As Double CubeVolume = Side * Side * Side End Function - Call Function ro ur Arguments Private Sub btnCalculate_Click() txtArea = CubeArea(txtSide) txtVolume = CubeVolume(txtSide) End Sub Parameter
  • 106. Management Information System SETEC University Page 104 of 140 Chapter 4: Creating and Using Form Lab: Procedures with Arguments: 1. Sub Procedure Sub SolveEllipse(SmallRadius As Double, LargeRadius As Double) Dim dblCircum As Double Dim dblArea As Double dblCircum = (SmallRadius + LargeRadius) * 2 dblArea = SmallRadius * LargeRadius * 3.14159 ‘2R txtEllipseCircumference = dblCircum txtEllipseArea = dblArea End Sub 2. Function Procedures Function BoxArea(dblLength As Double, _ dblHeight As Double, _ dblWidth As Double) As Double Dim Area As Double Area = 2 * ((dblLength * dblHeight) + _ (dblHeight * dblWidth) + _ (dblLength * dblWidth) _ ) BoxArea = Area End Function Function BoxVolume(dblLength As Double, _ dblHeight As Double, _ dblWidth As Double) As Double Dim Volume As Double Volume = dblLength * dblHeight * dblHeight BoxVolume = Volume End Function Homework HW1: Sub Procedure ១ HourW g ។ txtHours txtHWage txtResult btnE&xit
  • 107. SETEC University Management Information System Chapter 4: Creating and Using Form Page 105 of 140 Private Sub txtResult_GotFocus() Dim dblHours As Double Dim dblHWage As Double dblHours = txtHours dblHWage = txtHWage CalcAndShowSalary dblHours, dblHWage End Sub Sub CalcAndShowSalary(Hours As Double, HWage As Double) Dim dblResult As Double dblResult = Hours * HWage txtResult = dblResult End Sub Private Sub btnExit_Click() DoCmd.Close End Sub HW2: Function Procedure discount (Marked Price) (Discount Rate) ។ Function CalculateNetPrice(DiscountRate As Double) As Currency Dim OrigPrice As Double OrigPrice = CCur(txtMarkedPrice) CalculateNetPrice = OrigPrice - OrigPrice * DiscountRate End Function Private Sub cmdCalculate_Click() Dim dblDiscount Double dblDiscount = CDbl(txtDiscountRate) txtNetPrice = CalculateNetPrice(dblDiscount) End Sub
  • 108. Management Information System SETEC University Page 106 of 140 Chapter 4: Creating and Using Form 4.14. Conditional Statements - Here is a summary table of the logical operators we have studied: Operator Meaning Example Opposite = Equality to a = b Not Not Not equal to 12 <> 7 = < Less than 25 < 84 >= <= Less than or equal to Cab <= Tab > > Greater than 248 > 55 <= >= Greater than or equal to Val1 >= Val2 < - The If…Then Statement If Condition Then Statement : If Condition Then Statement1 Statement2 ……………… End If - The If…Then…Else Statement If Condition Then Statement1 Else Statement2 End If - The If…Then…ElseIf Statement If Condition1 Then Statement1 Else If Condition2 Then Statement2 Else If Condition3 Then Statement3 Else Statement4 End If
  • 109. SETEC University Management Information System Chapter 4: Creating and Using Form Page 107 of 140 Lab: Conditional Statements: 1. Password Form frmLogin Textboxs: - txtUserName - txtPassword, Inputmask: Password Command buttons: - btnLogin, Caption: L&ogin - btnClose, Caption: &Close 2. code event On_Click button: Login Private Sub btnLogin_Click() If txtUserName = "Sabay" And txtPassword = "1234" Then MsgBox "Welcome to my application" DoCmd.OpenForm "frmHourWage" Else txtPassword = "" txtUserName = "" txtUserName.SetFocus End If End Sub 3. code event On_Click button: Login Private Sub btnClose_Click() DoCmd.Close End Sub 4.15. Counting and Looping Structures: Looping Structures computer (Statements) ។ - Th Do Whil …Loop Do While Condition Statement(s) Loop
  • 110. Management Information System SETEC University Page 108 of 140 Chapter 4: Creating and Using Form E.g.: Private Sub cmdCounter_Click() Dim Number As Integer Do While Number < 46 MsgBox CStr(Number) Number = Number + 4 Loop MsgBox "Counting Stopped at " & CStr(Number) End Sub - Th Do…Loop Whil Do Statement(s) Loop While Condition E.g.: Private Sub cmdCounter_Click() Dim Answer As String Do Answer = CStr(InputBox("Are we there yet(1=Yes/0=No)?", "Counter", "1")) Loop While Answer <> "1" MsgBox "Wonderful, we have arrived" End Sub - Th Do Until…Loop Do Until Condition Statement(s) Loop E.g.: Private Sub cmdCounter_Click() Dim Answer As String Do Until (Answer = "1") Answer = InputBox("Are we there yet (1=Yes/0=No)?", _ "Counter", "1") Loop MsgBox "Wonderful, we have arrived" End Sub - Th Do…Loop Until Do Statement(s) Loop Until Condition - Th For… ext: For Counter = Start To End Step Increment Statement(s) Next Counter Note: To stop an endless loop, press ESC or CTRL+BREAK.
  • 111. SETEC University Management Information System Chapter 4: Creating and Using Form Page 109 of 140 4.16. Data Access Objects(DAO) 1. What is DAO? DAO Programming interface Microsoft Visual Basic database Microsoft Microsoft Access database ។ 2. Recordset object DAO records table query database ។ 3. Database Object : Dim DatabaseName AS DAO.Database E.g. : Dim db AS DAO.Database 4. Recordset Object : Dim RecordsetName AS DAO.Recordset E.g. : Dim rs AS DAO.Recordset 5. Database Object : Set db = CurrentDb() : Database Object ដ ើមបីភ្ជ ា ប់ Database ។ Set db = DAO.OpenData s “ thFil m .m ” Database Object Database ។ E.g. : Set db = DAO.OpenDatab s “D My DatabasesStudentDB.acc ” 6. Recordset Object S t rs = .Op nR or s t “T l |qu ry”, R or Typ *RecordType: - dbOpenDynaset: Open in Dynaset - dbOpenTable: Open in table (have index) - dbOpenSnapShot: Open in snapshot (read only)
  • 112. Management Information System SETEC University Page 110 of 140 Chapter 4: Creating and Using Form Lab1: DAO Form : - Form : - Database Recordset : Option Explicit Dim db As DAO.Database Dim rs As DAO.Recordset Sub showDT() txtSubjectID.Value = rs.Fields("SubjectID") txtSubjectName.Value = rs.Fields("SubjectName") txtDescription.Value = rs.Fields("Description") End Sub - Database Recordset Form_Load() : Private Sub Form_Load() Dim strSQL As String strSQL = "Select * from tblSubjects" Set db = CurrentDb Set rs = db.OpenRecordset(strSQL) Call showDT End Sub - code btnFirst (event: On_Click) record ១: Private Sub btnFirst_Click() rs.MoveFirst Call showDT End Sub - code btnLast (event: On_Click) record : Private Sub btnLast_Click() rs.MoveLast Call showDT End Sub txtSubjectID txtSubjectName txtDescription btnFirst btnPrevious btnNext btnLast
  • 113. SETEC University Management Information System Chapter 4: Creating and Using Form Page 111 of 140 - code btnNext (event: On_Click) record : Private Sub btnNext_Click() rs.MoveNext If Not rs.EOF Then Call showDT Else MsgBox "No more record" rs.MovePrevious End If End Sub - code btnPrevious (event: On_Click) record : Private Sub btnPrevious_Click() rs.MovePrevious If Not rs.BOF Then Call showDT Else MsgBox "First record reached" rs.MoveNext End If End Sub Lab 2: records : - code btnSearch (event: On_Click) records: Private Sub btnSearch_Click() Dim strCriteria As String strCriteria = "Select * from tblSubjects Where _ SubjectName='" _ & InputBox("Input SubjectName:") & "'" Set db = CurrentDb Set rs = db.OpenRecordset(strCriteria) If rs.EOF Then MsgBox "No record found!", vbInformation Else Call showDT End If End Sub btnSearch btnClear
  • 114. Management Information System SETEC University Page 112 of 140 Chapter 4: Creating and Using Form Lab 3: Add record : - code btnAdd (event: On_Click) Add records: Private Sub btnAdd_Click() Dim intSubjectID As Integer Dim strSubjectName As String Dim strDescription As String intSubjectID = InputBox("Input Subject ID:") strSubjectName = InputBox("Input Subject Name:") strDescription = InputBox("Input Description:") With rs .AddNew !SubjectID = intSubjectID !SubjectName = strSubjectName !Description = strDescription .Update .Close End With End Sub Lap 4: record : - code btnDelete (event: On_Click) Delete records: Private Sub btnDelete_Click() If MsgBox("Are you sure you want to delete this record?", vbYesNo, "Delete record") = vbYes Then rs.Delete Call btnPrevious_Click Else Exit Sub End If End Sub btnAdd btnDelete
  • 115. SETEC University Management Information System Chapter 4: Creating and Using Form Page 113 of 140 Lab 5: Update record: - code btnAdd (event: On_Click) Add records: Private Sub btnUpdate_Click() With rs .Edit !SubjectID = txtSubjectID !SubjectName = txtSubjectName !Description = txtDescription .Update End With End Sub *****End of Chapter 4***** btnUpdate
  • 116. Management Information System SETEC University Page 114 of 140 Chapter 5: Creating and Using Report Chapter 5 Creating and Using Report Report? Report Object MS-Access ដេញពី table query ។ 5.1. R port Report tool: 1. Navigation Pane, Table Query Report 2. Ribbon, tab: Create  Reports, icon: Report Report Layout View : 3. Save Save report 5.2. View Report 1. Navigation Pane, Double-click Report Report view Report View
  • 117. SETEC University Management Information System Chapter 5: Creating and Using Report Page 115 of 140 2. Ribbon, tab: Home  Views, icon: View : icons Status bar - Report View: Report Print Report Clipboard
  • 118. Management Information System SETEC University Page 116 of 140 Chapter 5: Creating and Using Report - Print Preview: Report Print - Layout View: Report (design) ។ - Design View: Report (formatting) Layout View ។
  • 119. SETEC University Management Information System Chapter 5: Creating and Using Report Page 117 of 140 5.3. R port Report Wizard 1. Ribbon, tab: Create  Report, icon: Report Wizard ។ Wizard : 2. “T l s u ri s” , t l query 3. List “Av il l Fi l s”, fields Report ។ Report fields table query “T l s u ri s” table/query fields ។ 4. Next
  • 120. Management Information System SETEC University Page 118 of 140 Chapter 5: Creating and Using Report 5. field grouping levels  Next 6. fields (Sort) Detail records  Next
  • 121. SETEC University Management Information System Chapter 5: Creating and Using Report Page 119 of 140 7. Layout Orientation Report - Stepped: - Block:
  • 122. Management Information System SETEC University Page 120 of 140 Chapter 5: Creating and Using Report - Outline: 8. Next 9. Style  Next
  • 123. SETEC University Management Information System Chapter 5: Creating and Using Report Page 121 of 140 10. Report  “ r vi w th r port” 11. Finish 5.4. Label Label Wizard 1. Navigation Pane, Double-click table query Label 2. Ribbon, tab: Create  Reports, icon: Label 3. Label Wizard :
  • 124. Management Information System SETEC University Page 122 of 140 Chapter 5: Creating and Using Report 4. Label  Next 5. Text Label  Next 6. fields mailing label  Next
  • 125. SETEC University Management Information System Chapter 5: Creating and Using Report Page 123 of 140 7. field (Sort)  Next 8. Report  “S th l ls s th y will look print ” 9. Finish
  • 126. Management Information System SETEC University Page 124 of 140 Chapter 5: Creating and Using Report 5.5. R port Blank Report tool: 1. Ribbon, tab: Create  Report, icon: Blank Report 2. Field List pane, (+) Table fields table 3. Double-click field Report ។ fields key: Ctrl + fields ។ 4. tools Control tab: Format Logo, , Report ។
  • 127. SETEC University Management Information System Chapter 5: Creating and Using Report Page 125 of 140 5.6. Report Sections: Report :  Report Header: Report ។ Logo, ។  Page Header ។ Report ។  Group Header Records ។ Records ។  Detail Row Record Source ។  Group Footer: Records ។ (Aggregate Functions) ។  Page Footer ។ ។  Report Footer: Report ។ Report ។
  • 128. Management Information System SETEC University Page 126 of 140 Chapter 5: Creating and Using Report 5.7. Grouped Report Report Wizard:  Record Source: 1. Select Query tables: Customers Orders fields: 2. Save query qryTotal Freight by Shipped Date  Report Wizard: 1. Ribbon, tab: Create  Report, icon: Report Wizard Wizard Report :
  • 129. SETEC University Management Information System Chapter 5: Creating and Using Report Page 127 of 140 2. Tables/Queries, table query Record Source Report 3. list “Av il l Fi l s”, fields Report  Next 4.  Next
  • 130. Management Information System SETEC University Page 128 of 140 Chapter 5: Creating and Using Report 5. field group - field (Data Type) Date/Time i on Grouping Options … Grouping intervals - OK 6. Next
  • 131. SETEC University Management Information System Chapter 5: Creating and Using Report Page 129 of 140 7. fields (Sort) Detail records - i on Summ ry Options … - Aggregate function (Sum, Avg, Min Max) - OK 8. Next
  • 132. Management Information System SETEC University Page 130 of 140 Chapter 5: Creating and Using Report 9. Layout Orientation Report St pp , lo k, Outlin … 10. Next 11. Style  Next
  • 133. SETEC University Management Information System Chapter 5: Creating and Using Report Page 131 of 140 12. Report  “ r vi w th r port” 13. Finish Lab: េូរបដ្កើត report មួយ ូេរូបខា្ដរោម ៖
  • 134. Management Information System SETEC University Page 132 of 140 Chapter 5: Creating and Using Report Solution: 5.8. Homeworks 1. បដ្កើត tblCustomers ដ ើមបីផ្ទុកព័ត៌មានអ្ំពីអ្តិថិជន 2. បដ្កើត tblProducts ដ ើមបីផ្ទុកព័ត៌មានអ្ំពីផ្លិតផ្ល 3. បដ្កើត tblOrders ដ ើមបីផ្ទុកព័ត៌មានអ្ំពីោរបញ្ជ ា ទិញទំនិញពីអ្តិថិជន
  • 135. SETEC University Management Information System Chapter 5: Creating and Using Report Page 133 of 140 4. បដ្កើត tblOrderDetails ដ ើមបីផ្ទុកព័ត៌មានបន្នែមអ្ំពីោរបញ្ជ ា ទិញទំនិញពីអ្តិថិជន ដោយរួម បញ្ចូលទំ្ទំនិញន្ លអ្តិថិជនទិញ ។ 5. បដ្កើត relationships រវា្ tables : 6. បដ្កើត frmOrderDetailProductSub ដេញពី tblOrderDetail និ្ tblProducts រួេគណនារក Sub Total និ្ Total ូេខា្ដរោម :
  • 136. Management Information System SETEC University Page 134 of 140 Chapter 5: Creating and Using Report 7. បដ្កើត frmOrders ដេញពី tblOrders រួេទញ Subform: frmOrderDetailProductSub ន្ ល បានបដ្កើតរួេខា្ដលើោក់េូល ូេខា្ដរោម : 8. បដ្កើត frmCustomerOrder (Mainform) ដេញពី tblCustomers រពមទំ្គូស combobox មួយសំរាប់ ន្សវ្រកតាមរយៈ ដ្ ម ោះអ្តិថិជន ។ a. សរដសរ code បដ្កើត event: After_Update ដលើ cboSearch ូេខា្ដរោម : Private Sub cboSearch_AfterUpdate() Dim SQL As String SQL = "Select * from tblCustomers Where CustomerName='" _ & cboSearch & "'" Form_frmCustomerOrder.RecordSource = SQL End Sub b. ទញ frmOrder ន្ លបានបដ្កើតដ ើ្ខា្ដលើ ោក់ជា subform កនុ្ frmCustomerOrder រួេគូស buttons ពីរ ូេរូបខា្ដរោម : cboSearch frmOrders frmOrderDetailProducttSub
  • 137. SETEC University Management Information System Chapter 5: Creating and Using Report Page 135 of 140 c. សរដសរ code បដ្កើត event: On_Click ដលើ btnPreviewReport ូេខា្ដរោម : Private Sub btnPreviewReport_Click() DoCmd.OpenReport "rptCustomerOrder", acViewReport, , _ "CustomerID=" & Me.CustomerID End Sub d. សរដសរ code បដ្កើត event: On_Click ដលើ btnPrintReport ូេខា្ដរោម ៖ Private Sub btnPrintReport_Click() DoCmd.OpenReport "rptCustomerOrder", acViewNormal, , _ "CustomerID=" & Me.CustomerID End Sub សំគាល់ៈ - acViewReport: សំរាប់ បង្ហ ា ញ report កនុ្ Print Preview - acViewNormal: សំរាប់ print report - េូរអ្នុវតតេំនុេ c និ្ d ដរោយដពលបដ្កើត report រួេ ។ 9. បដ្កើត rptOrderDetailProductSub ដេញពី tblOrderDetail និ្ tblProducts រួេគណនារក Sub Total និ្ Total ូេខា្ដរោម : frmCustomerOrder frmOrders btnPrintReport btnPreviewReport
  • 138. Management Information System SETEC University Page 136 of 140 Chapter 5: Creating and Using Report 10.បដ្កើត rptOrders ដេញពី tblOrders រួេទញ Subreport: rptOrderDetailProductSub ន្ ល បានបដ្កើតរួេខា្ដលើោក់េូល ូេរូបខា្ដរោម : 11.បដ្កើត rptCustomerOrder (Mainreport) ដេញពី tblCustomers :  ទញ rptOrder ន្ លបានបដ្កើតដ ើ្ខា្ដលើ ោក់ជា subreport កនុ្ rptCustomerOrder ូេរូបខា្ដរោម : rptOrders rptOrderDetailProducttSub
  • 139. SETEC University Management Information System Chapter 5: Creating and Using Report Page 137 of 140 12.រដបៀបកំនត់ដលខដរៀ្ដោយបង្ហ ា ញដោយសវ័យរបវតតន៍តាមរកុម (Over Group) : a. ដបើក rptOrderDetailProductSub កនុ្ Design View រួេគូស textbox មួយដលើផ្ផ្ទ Detail ដោយោក់ដ្ ម ោះ txtNo ូេខា្ដរោម : rptCustomerOrder rptOrders
  • 140. Management Information System SETEC University Page 138 of 140 Chapter 5: Creating and Using Report b. កំនត់ property របស់ txtNo : - Control Source: =1 - Running Sum: Over Group ***End of Chapter 5***