140
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

Table of Contents - KhmerDocs · 2017. 7. 3. · Page 4 of 140 Chapter 1: Introduction to MS-Access 2007 Program Window MS-Access 2007 - The Ribbon: Program Window Commands ។ -

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

  • 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 Files\Microsoft Office\Office12 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

    >:

  • 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

  • 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: ។

    : >,

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

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

    mk:@MSITStore:C:/Program%20Files/Microsoft%20Office/OFFICE11/1033/acmain11.chm::/html/jetglossary.htm#idh_dadefmsjetdatabaseengine

  • 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 '

  • 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