SlideShare une entreprise Scribd logo
1  sur  63
Enhancing User Interaction Through Programming Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach  1 Chapter 7 “I like thinking big. If you’re going to be thinking anything, youmight as well think big.”—Donald Trump
Chapter Introduction Visual basic for applications (VBA) Fully customize and automate a database Perform more complex validity Use functions and actions not available with macros Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach  2
Tools Covered in This Chapter Assignment statement  Breakpoints Code window  DateDiff function  DateSerial function Debug DoCmd statement Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach  3
Tools Covered in This Chapter (continued) If statement Immediate window Northwind sample database Variables Visual Basic editor Watches window Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach  4
Level 1 Objectives:Writing Visual Basic for Applications Code Design create and test a subroutine in a standard module Design create, and test an event procedure Analyze decisions using procedures Design create, and test a function in a standard module Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach  5
Understanding Visual Basic for Applications Programming language for Microsoft Office programs  Including Access Common syntax and set of common features for all Microsoft Office programs Features unique for each Microsoft Office program Use programming language Write set of instructions to direct computer to perform specific operations in specific order Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach  6
Understanding Visual Basic for Applications (continued) Coding Statement Event-driven language Object-oriented language Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach  7
Event-Driven Programming Event  State condition or occurrence that Access recognizes Has associated event property Appear in property sheet for forms reports, and controls Create group of statements using VBA code  Set event property value to name of that group of statements Event procedure Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach  8
Frequently Used Access Events Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach  9
Common Events for Selected Controls Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach  10
Coding VBA Types of procedures  Function procedures Performs operations  Returns value  Accepts input values  Can be used in expressions Sub procedures Performs operations and accepts input values  Does not return value  Cannot be used in expressions Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach  11
Coding VBA (continued) Module Group of related procedures Starts with declarations section One or more procedures Basic types of modules  Standard modules Database object stored in memory Use from anywhere in database Class modules Usually associated with particular form or report Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach  12
Coding VBA (continued) Public procedure More than one object can use Local procedure or a private procedure  Only the form or report for which class module created can use event procedure Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach  13
Creating a Subroutine in a Standard Module Replace macros with VBA procedures Some tasks cannot be performed with VBA AutoKeys AutoExec Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach  14
Creating a New Standard Module Click Create tab Click Macro button arrow, and then click Module Begin new procedure in module Click Insert menu Click procedure Type name Select options Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach  15
Creating a New Standard Module (continued) Visual Basic Editor Create and modify VBA code Visual Basic window  Program window that opens within VBE Code window  Window to create modify and display specific VBA procedures Can have as many code windows open as modules in database Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach  16
Creating a New Standard Module (continued) Sub statement  Ends with end sub statement Includes  Scope of procedure Name of procedure  Opening and closing parenthesis Option compare statement  Designates technique access uses to compare and sort text data Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach  17
Creating a Subroutine Type statements in procedure between Sub and End Sub statements DoCmd statement Executes action in procedure Access object Method  Action that operates on specific objects or controls Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach  18
Creating a Subroutine (continued) Comment  Include anywhere in VBA procedure  Describe what procedure or statement does Make it easier for programmers to identify purpose of statements Begin comment with  Word Rem (for “remark”)  Or single quotation mark (') Appear green in code window Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach  19
Creating a Subroutine (continued) Line label Statement that serves as starting point for block of statements in procedure Begins at start of line and ends with colon Underscore character at end of line Statement continues to next line Run procedure Click Run Sub/UserForm button Saves module Click Save button Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach  20
Creating an Event Procedure Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach  21
Designing an Event Procedure Associate procedure with form’s On Current event property Triggered when form’s Current event occurs Occurs when focus moves to record  Add event procedure Open property sheet for form Click On Current text box Click list arrow Click [event procedure] Click Build button to right of On Current text box Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach  22
Making Decisions Using the If Statement Decision-making statement  Executes group of statements based on outcome of condition Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach  23
Making Decisions Using the If Statement (continued) If statement Tests condition follows one of two paths depending on outcome of condition General form If condition Then True-statement group [Else False-statement group] End If Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach  24
Making Decisions Using the If Statement (continued) Assignment statement  Assigns value of expression to control or property Example EstSalary.ForeColor = vbGreen ForeColor property Color constants Predefined VBA names  Have values that represent system color value IsNull functions returns True value when field or control null False when not Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach  25
Comparison Operators and How to Use Them in Conditions Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach  26
Testing an Event Procedure Switch to form view Navigate through records  Make sure results correct in different situations Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach  27
Creating a Function Similar calculation requests Create function to perform calculation  Function  Begins with Function statement  Ends with End Function statement Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach  28
Variables Named location in computer memory  Can contain value Use to store and retrieve data Reference using variable name assigned to location Holds only one value at a time Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach  29
Variables (continued) Naming rules Must begin with letter Cannot exceed 255 characters Include letters numbers and underscore character  Cannot use space, punctuation, or special characters Cannot be same as keywords or reserved words Each variable has data type Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach  30
Common VBA Data Types Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach  31
Using Functions Similar to way built-in functions used Call a function Function name followed by argument(s) Commas separate multiple arguments DateDiff function Calculates number of time intervals between two dates Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach  32
Testing a Function in the Immediate Window When statement entered Editor checks statement to make sure syntax correct Logic error  Occurs when procedure produces incorrect results Immediate window Test VBA procedures without changing data in database Enter different values to test procedure Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach  33
Testing a Function in the Immediate Window (continued) Immediate window Type keyword “print” or question mark (?)  Followed by procedure name and argument values to test in parentheses and separated by commas DateSerial function  Returns date value for specified year, month, and day Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach  34
Level 1 Summary VBA Programming language for Microsoft Office programs Create procedures in module Event-driven programming Program statement execution triggered by events If statement Used to make decisions Function Returns a value Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach  35
Level 2 Objectives:Using Custom Functions and Verifying Data Design create and test a custom function in an event procedure Use ElseIf and If statements Verify data using event procedures Use the Case control structure Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach  36
Enhancing an Event Procedure to Use a Custom Function Add and change statements in a procedure Open object that contains event procedure in Design view Click View Code button on Design Ribbon Add new procedure module or class module Click Insert on menu bar  Click Procedure, Module, or Class Module Edit existing statements Scroll code window to desired statement  Make necessary changes Press Save button on Visual Basic toolbar Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach  37
Using an ElseIf Statement in an If Statement Date function Returns current computer system date ElseIf statement  Equivalent to Else clause followed by If statement Choice of which If statement version used  Matter of personal preference Arranging order of condition testing Order of condition testing critical Place conditions in order from least inclusive to most inclusive Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach  38
Comparing an ElseIf Clause to an Else…if Clause Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach  39
Using an ElseIf Statement in an if Statement (continued) Dim statement Declare variables and associated data types in procedure Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach  40
Verifying Data with VBA Before Update event  Occurs before changed data in control or record updated in database Use to verify entered data Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach  41
Designing the Field Validation Procedure to Verify Zip Codes Cancel As Integer  Defines Cancel as parameter with Integer data type For some events access executes attached event procedure before performing default behavior Can cancel default behavior in event procedure or macro Using Cancel parameter Left function  Returns string containing specified number of characters from left side of specified string Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach  42
Designing the Field Validation Procedure to Verify Zip Codes (continued) Val function  Returns numbers contained in specified string as numeric value Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach  43
Using the Case Control Structure Control structure  Set of VBA statements work together as a unit Case control structure Evaluates expression Performs one of several alternative sets of statements  Based on resulting value (or condition) of evaluated expression Use Case Else statement as last Case statement Include false-statement group Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach  44
Using the Case Control Structure (continued) CancelEvent action  Cancels event that caused procedure or macro containing action to execute Me keyword  Refers to current object Undo  Method that clears all changes made to current record SetFocus  Moves focus to specified object or control Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach  45
Testing the Field Validation Procedure to Verify Zip Codes Switch to form view to test validation procedure Using event procedure for control or form Before Update event for each control on form Need two or more fields as part of validation process Use form’s Before Update event Disadvantage All changes made to record undone Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach  46
Designing the Field Validation Procedure to Verify Phone Area Codes Message can suggest potential error Must accept any phone area code entry Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach  47
Level 2 Summary ElseIf statement  Verify data using VBA Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach  48
Level 3 Objectives: Testing and Exploring VBA Troubleshoot problems in VBA procedures Compile modules Develop sources for learning VBA Explore completed modules in the Northwind sample database Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach  49
Troubleshooting VBA Procedures Syntax error  Occurs when VBA statement violates language rules for statement such as  Misspelling  Incorrect sequence of keywords Missing parenthesis Detected immediately when statement completed Error message opens and explains error Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach  50
Syntax Error Message Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach  51
Troubleshooting VBA Procedures (continued) Compilation error  Occurs when procedures translated into form computer can understand Compilation Process of translating modules from VBA to form computer understands Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach  52
Troubleshooting VBA Procedures (continued) Prevent compilation errors at run time Use Compile command on Debug menu  Compile as last step before saving module Execution error or run-time error  Occurs when procedure executes and stops because it tries to perform operation that is impossible to perform Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach  53
Using the Debugger to Correct Errors Breakpoint  Run subroutine or function up until line on which breakpoint set  Procedure halts execution at point and displays module screen Good way to isolate place at which procedure stops producing anticipated result Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach  54
Using the Debugger to Correct Errors (continued) Use mouse pointer to get more information about procedure Pointing to variable name displays ScreenTip with value contained in variable at point that procedure halted Execute procedure one statement at a time Try and identify cause of error  Click Debug on menu bar Click Step Into Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach  55
Using the Debugger to Correct Errors (continued) Step Into Procedure executes next statement and stops Step Out Executes current subroutine or function and then halts Reset button Stops debugger so you can fix problem Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach  56
Identifying Errors Using the Watches Window Watches window  Shows current value of specified variable Add Watch dialog box Enter variable name to watch “<Out of context>” in value column  Appears for watch expression  When access not executing procedure that contains watch expression Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach  57
Add Watch Dialog Box Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach  58
Building Procedures Slowly to Isolate Problems Prevent problems in procedures  Build them slowly using small groups of statements Prove them to be correct as you go Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach  59
Using Help to Learn More About Programming and VBA Access Help contains valuable information about VBA Reading individual topics gives excellent background Search results list Sample code for situations Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach  60
Visual Basic Help Table Of Contents Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach  61
Level 3 Summary Errors Syntax  Compilation Execution or run-time Debugger Use to find and correct errors Help Learn more about VBA Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach  62
Chapter Summary VBA Programming language for Microsoft Office applications Decision structures If ElseIf Case Develop subroutines Use debugger to find errors Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach  63

Contenu connexe

Tendances

Lecture2 slides
Lecture2 slidesLecture2 slides
Lecture2 slidesCyri Jones
 
Microsoft dynamics ax2012 : forms and tables methods call sequences, How To?
Microsoft dynamics ax2012 : forms and tables methods call sequences, How To?Microsoft dynamics ax2012 : forms and tables methods call sequences, How To?
Microsoft dynamics ax2012 : forms and tables methods call sequences, How To?Mohamed Amine HAMDAOUI
 
Access 2013 Unit A
Access 2013 Unit AAccess 2013 Unit A
Access 2013 Unit Ajarana00
 
Sample sales reengineering in obiee 11g part i and part ii
Sample sales reengineering in obiee 11g  part i and part iiSample sales reengineering in obiee 11g  part i and part ii
Sample sales reengineering in obiee 11g part i and part iiAmit Sharma
 
Access lesson05
Access lesson05Access lesson05
Access lesson05Aram SE
 
Access lesson 01 Microsoft Access Basics
Access lesson 01 Microsoft Access BasicsAccess lesson 01 Microsoft Access Basics
Access lesson 01 Microsoft Access BasicsAram SE
 
MS Access teaching powerpoint tasks
MS Access teaching powerpoint tasksMS Access teaching powerpoint tasks
MS Access teaching powerpoint tasksskomadina
 
Access lesson 04 Creating and Modifying Forms
Access lesson 04 Creating and Modifying FormsAccess lesson 04 Creating and Modifying Forms
Access lesson 04 Creating and Modifying FormsAram SE
 
Access2007 part1
Access2007 part1Access2007 part1
Access2007 part1jigeno
 
New Perspectives: Access.01
New Perspectives: Access.01New Perspectives: Access.01
New Perspectives: Access.01Anna Stirling
 
Fomatting Text Tips
Fomatting Text TipsFomatting Text Tips
Fomatting Text TipsEMAINT
 
Apps 11i10 Forms Personalization
Apps 11i10 Forms PersonalizationApps 11i10 Forms Personalization
Apps 11i10 Forms PersonalizationHossam El-Faxe
 
Access 2010 Unit A PPT
Access 2010 Unit A PPTAccess 2010 Unit A PPT
Access 2010 Unit A PPTokmomwalking
 
Access lesson 02 Creating a Database
Access lesson 02 Creating a DatabaseAccess lesson 02 Creating a Database
Access lesson 02 Creating a DatabaseAram SE
 

Tendances (18)

Lecture2 slides
Lecture2 slidesLecture2 slides
Lecture2 slides
 
Microsoft dynamics ax2012 : forms and tables methods call sequences, How To?
Microsoft dynamics ax2012 : forms and tables methods call sequences, How To?Microsoft dynamics ax2012 : forms and tables methods call sequences, How To?
Microsoft dynamics ax2012 : forms and tables methods call sequences, How To?
 
Mca 504 dotnet_unit5
Mca 504 dotnet_unit5Mca 504 dotnet_unit5
Mca 504 dotnet_unit5
 
Access 2007 Unit B
Access 2007 Unit BAccess 2007 Unit B
Access 2007 Unit B
 
Access 2013 Unit A
Access 2013 Unit AAccess 2013 Unit A
Access 2013 Unit A
 
Sample sales reengineering in obiee 11g part i and part ii
Sample sales reengineering in obiee 11g  part i and part iiSample sales reengineering in obiee 11g  part i and part ii
Sample sales reengineering in obiee 11g part i and part ii
 
Access.05
Access.05Access.05
Access.05
 
Access lesson05
Access lesson05Access lesson05
Access lesson05
 
Access lesson 01 Microsoft Access Basics
Access lesson 01 Microsoft Access BasicsAccess lesson 01 Microsoft Access Basics
Access lesson 01 Microsoft Access Basics
 
MS Access teaching powerpoint tasks
MS Access teaching powerpoint tasksMS Access teaching powerpoint tasks
MS Access teaching powerpoint tasks
 
Access lesson 04 Creating and Modifying Forms
Access lesson 04 Creating and Modifying FormsAccess lesson 04 Creating and Modifying Forms
Access lesson 04 Creating and Modifying Forms
 
Access2007 part1
Access2007 part1Access2007 part1
Access2007 part1
 
New Perspectives: Access.01
New Perspectives: Access.01New Perspectives: Access.01
New Perspectives: Access.01
 
Template builder for word tutorial
Template builder for word tutorialTemplate builder for word tutorial
Template builder for word tutorial
 
Fomatting Text Tips
Fomatting Text TipsFomatting Text Tips
Fomatting Text Tips
 
Apps 11i10 Forms Personalization
Apps 11i10 Forms PersonalizationApps 11i10 Forms Personalization
Apps 11i10 Forms Personalization
 
Access 2010 Unit A PPT
Access 2010 Unit A PPTAccess 2010 Unit A PPT
Access 2010 Unit A PPT
 
Access lesson 02 Creating a Database
Access lesson 02 Creating a DatabaseAccess lesson 02 Creating a Database
Access lesson 02 Creating a Database
 

En vedette

Unit 3 consumer_decision_making
Unit 3 consumer_decision_makingUnit 3 consumer_decision_making
Unit 3 consumer_decision_makingZaha World
 
Management Yesterday And Today 2 P O M
Management  Yesterday And  Today 2  P O MManagement  Yesterday And  Today 2  P O M
Management Yesterday And Today 2 P O MZoha Qureshi
 
Chapter 18 Managing Operations Ppt18
Chapter 18 Managing Operations Ppt18Chapter 18 Managing Operations Ppt18
Chapter 18 Managing Operations Ppt18D
 
Stu Rc8e Ch02
Stu Rc8e Ch02Stu Rc8e Ch02
Stu Rc8e Ch02D
 
Stu Rc8e Ch01[1]
Stu Rc8e Ch01[1]Stu Rc8e Ch01[1]
Stu Rc8e Ch01[1]D
 
Unit 5 segmenting_and_targeting_market(2)
Unit 5 segmenting_and_targeting_market(2)Unit 5 segmenting_and_targeting_market(2)
Unit 5 segmenting_and_targeting_market(2)Zaha World
 
Stu Rc8e Ch03
Stu Rc8e Ch03Stu Rc8e Ch03
Stu Rc8e Ch03D
 
Chapter 17 Intro To Controlling Ppt17
Chapter 17 Intro To Controlling Ppt17Chapter 17 Intro To Controlling Ppt17
Chapter 17 Intro To Controlling Ppt17D
 
Unit 1 marketing_overview-2
Unit 1 marketing_overview-2Unit 1 marketing_overview-2
Unit 1 marketing_overview-2Zaha World
 
Unit 4 consumer_decision_making
Unit 4 consumer_decision_makingUnit 4 consumer_decision_making
Unit 4 consumer_decision_makingZaha World
 
Chapter 19 Ppt19
Chapter 19 Ppt19Chapter 19 Ppt19
Chapter 19 Ppt19D
 
Fundamental of Management. Lecture 2
Fundamental of Management. Lecture 2Fundamental of Management. Lecture 2
Fundamental of Management. Lecture 2Zaha World
 
Chapter 14 Managers And Communication Ppt14
Chapter 14 Managers And Communication Ppt14Chapter 14 Managers And Communication Ppt14
Chapter 14 Managers And Communication Ppt14D
 
Project Management Fundamental
Project Management FundamentalProject Management Fundamental
Project Management FundamentalAndy Pham, PMP
 
Chapter 4 Managing In A Global Environmen Ppt04
Chapter 4 Managing In A Global Environmen Ppt04Chapter 4 Managing In A Global Environmen Ppt04
Chapter 4 Managing In A Global Environmen Ppt04D
 
Blast 1998 sept_2001_pak
Blast 1998 sept_2001_pakBlast 1998 sept_2001_pak
Blast 1998 sept_2001_pakMalik Saif
 
Chapter 3 Organiz Culture And Environ The Constraints Ppt03
Chapter 3 Organiz Culture And Environ The Constraints Ppt03Chapter 3 Organiz Culture And Environ The Constraints Ppt03
Chapter 3 Organiz Culture And Environ The Constraints Ppt03D
 
Chapter 5 Social Responsibility And Managerial Ethics Ppt05
Chapter 5 Social Responsibility And Managerial Ethics Ppt05Chapter 5 Social Responsibility And Managerial Ethics Ppt05
Chapter 5 Social Responsibility And Managerial Ethics Ppt05D
 
Poverty in pakistan_revised_
Poverty in pakistan_revised_Poverty in pakistan_revised_
Poverty in pakistan_revised_Malik Saif
 

En vedette (20)

Unit 3 consumer_decision_making
Unit 3 consumer_decision_makingUnit 3 consumer_decision_making
Unit 3 consumer_decision_making
 
Management Yesterday And Today 2 P O M
Management  Yesterday And  Today 2  P O MManagement  Yesterday And  Today 2  P O M
Management Yesterday And Today 2 P O M
 
Chapter 18 Managing Operations Ppt18
Chapter 18 Managing Operations Ppt18Chapter 18 Managing Operations Ppt18
Chapter 18 Managing Operations Ppt18
 
Stu Rc8e Ch02
Stu Rc8e Ch02Stu Rc8e Ch02
Stu Rc8e Ch02
 
Stu Rc8e Ch01[1]
Stu Rc8e Ch01[1]Stu Rc8e Ch01[1]
Stu Rc8e Ch01[1]
 
Unit 5 segmenting_and_targeting_market(2)
Unit 5 segmenting_and_targeting_market(2)Unit 5 segmenting_and_targeting_market(2)
Unit 5 segmenting_and_targeting_market(2)
 
Stu Rc8e Ch03
Stu Rc8e Ch03Stu Rc8e Ch03
Stu Rc8e Ch03
 
Chapter 17 Intro To Controlling Ppt17
Chapter 17 Intro To Controlling Ppt17Chapter 17 Intro To Controlling Ppt17
Chapter 17 Intro To Controlling Ppt17
 
Unit 2
Unit 2Unit 2
Unit 2
 
Unit 1 marketing_overview-2
Unit 1 marketing_overview-2Unit 1 marketing_overview-2
Unit 1 marketing_overview-2
 
Unit 4 consumer_decision_making
Unit 4 consumer_decision_makingUnit 4 consumer_decision_making
Unit 4 consumer_decision_making
 
Chapter 19 Ppt19
Chapter 19 Ppt19Chapter 19 Ppt19
Chapter 19 Ppt19
 
Fundamental of Management. Lecture 2
Fundamental of Management. Lecture 2Fundamental of Management. Lecture 2
Fundamental of Management. Lecture 2
 
Chapter 14 Managers And Communication Ppt14
Chapter 14 Managers And Communication Ppt14Chapter 14 Managers And Communication Ppt14
Chapter 14 Managers And Communication Ppt14
 
Project Management Fundamental
Project Management FundamentalProject Management Fundamental
Project Management Fundamental
 
Chapter 4 Managing In A Global Environmen Ppt04
Chapter 4 Managing In A Global Environmen Ppt04Chapter 4 Managing In A Global Environmen Ppt04
Chapter 4 Managing In A Global Environmen Ppt04
 
Blast 1998 sept_2001_pak
Blast 1998 sept_2001_pakBlast 1998 sept_2001_pak
Blast 1998 sept_2001_pak
 
Chapter 3 Organiz Culture And Environ The Constraints Ppt03
Chapter 3 Organiz Culture And Environ The Constraints Ppt03Chapter 3 Organiz Culture And Environ The Constraints Ppt03
Chapter 3 Organiz Culture And Environ The Constraints Ppt03
 
Chapter 5 Social Responsibility And Managerial Ethics Ppt05
Chapter 5 Social Responsibility And Managerial Ethics Ppt05Chapter 5 Social Responsibility And Managerial Ethics Ppt05
Chapter 5 Social Responsibility And Managerial Ethics Ppt05
 
Poverty in pakistan_revised_
Poverty in pakistan_revised_Poverty in pakistan_revised_
Poverty in pakistan_revised_
 

Similaire à Ch07 Access

MS Access – Part 1 (One Day Workshop)
MS Access – Part 1 (One Day Workshop)MS Access – Part 1 (One Day Workshop)
MS Access – Part 1 (One Day Workshop)Khader Shaik
 
Lab Management with TFS 2010
Lab Management with TFS 2010Lab Management with TFS 2010
Lab Management with TFS 2010Ed Blankenship
 
Moving to Microsoft Visual Basic .NET
Moving to Microsoft Visual Basic .NETMoving to Microsoft Visual Basic .NET
Moving to Microsoft Visual Basic .NETV Sanchez
 
AD207 Presentation
AD207 PresentationAD207 Presentation
AD207 Presentationmackejo1
 
Better User Experience with .NET
Better User Experience with .NETBetter User Experience with .NET
Better User Experience with .NETPeter Gfader
 
Full Testing Experience - Visual Studio and TFS 2010
 Full Testing Experience - Visual Studio and TFS 2010 Full Testing Experience - Visual Studio and TFS 2010
Full Testing Experience - Visual Studio and TFS 2010Ed Blankenship
 
Office As A Development Platform
Office As A Development PlatformOffice As A Development Platform
Office As A Development PlatformChristof Sprenger
 
Alm Specialist Toolkit Team System 2008 Deep Dive
Alm Specialist Toolkit   Team System 2008 Deep DiveAlm Specialist Toolkit   Team System 2008 Deep Dive
Alm Specialist Toolkit Team System 2008 Deep DiveChristian Thilmany
 
Pega robotics best practices building solutions (1)
Pega robotics best practices   building solutions (1)Pega robotics best practices   building solutions (1)
Pega robotics best practices building solutions (1)KPMG US
 
Pega Robotics Training @Phno: whatsapp @8142976573.
Pega Robotics Training @Phno: whatsapp @8142976573.Pega Robotics Training @Phno: whatsapp @8142976573.
Pega Robotics Training @Phno: whatsapp @8142976573.Santhoo Vardan
 
Sww 2008 Automating Your Designs Excel, Vba And Beyond
Sww 2008   Automating Your Designs   Excel, Vba And BeyondSww 2008   Automating Your Designs   Excel, Vba And Beyond
Sww 2008 Automating Your Designs Excel, Vba And BeyondRazorleaf Corporation
 
AVB201.1 MS Access VBA Module 1
AVB201.1 MS Access VBA Module 1AVB201.1 MS Access VBA Module 1
AVB201.1 MS Access VBA Module 1guest38bf
 

Similaire à Ch07 Access (20)

Ch07 cmpt110
Ch07 cmpt110Ch07 cmpt110
Ch07 cmpt110
 
Visual basics
Visual basicsVisual basics
Visual basics
 
MS Access – Part 1 (One Day Workshop)
MS Access – Part 1 (One Day Workshop)MS Access – Part 1 (One Day Workshop)
MS Access – Part 1 (One Day Workshop)
 
Excel 2007 Unit P
Excel 2007 Unit PExcel 2007 Unit P
Excel 2007 Unit P
 
008.module
008.module008.module
008.module
 
Lab Management with TFS 2010
Lab Management with TFS 2010Lab Management with TFS 2010
Lab Management with TFS 2010
 
Moving to Microsoft Visual Basic .NET
Moving to Microsoft Visual Basic .NETMoving to Microsoft Visual Basic .NET
Moving to Microsoft Visual Basic .NET
 
Vs2008 Ms Lux
Vs2008 Ms LuxVs2008 Ms Lux
Vs2008 Ms Lux
 
Vs2008 Ms Lux
Vs2008 Ms LuxVs2008 Ms Lux
Vs2008 Ms Lux
 
AD207 Presentation
AD207 PresentationAD207 Presentation
AD207 Presentation
 
Better User Experience with .NET
Better User Experience with .NETBetter User Experience with .NET
Better User Experience with .NET
 
Full Testing Experience - Visual Studio and TFS 2010
 Full Testing Experience - Visual Studio and TFS 2010 Full Testing Experience - Visual Studio and TFS 2010
Full Testing Experience - Visual Studio and TFS 2010
 
Vb6.0 intro
Vb6.0 introVb6.0 intro
Vb6.0 intro
 
Office As A Development Platform
Office As A Development PlatformOffice As A Development Platform
Office As A Development Platform
 
Alm Specialist Toolkit Team System 2008 Deep Dive
Alm Specialist Toolkit   Team System 2008 Deep DiveAlm Specialist Toolkit   Team System 2008 Deep Dive
Alm Specialist Toolkit Team System 2008 Deep Dive
 
Pega robotics best practices building solutions (1)
Pega robotics best practices   building solutions (1)Pega robotics best practices   building solutions (1)
Pega robotics best practices building solutions (1)
 
Pega Robotics Training @Phno: whatsapp @8142976573.
Pega Robotics Training @Phno: whatsapp @8142976573.Pega Robotics Training @Phno: whatsapp @8142976573.
Pega Robotics Training @Phno: whatsapp @8142976573.
 
Sww 2008 Automating Your Designs Excel, Vba And Beyond
Sww 2008   Automating Your Designs   Excel, Vba And BeyondSww 2008   Automating Your Designs   Excel, Vba And Beyond
Sww 2008 Automating Your Designs Excel, Vba And Beyond
 
AVB201.1 MS Access VBA Module 1
AVB201.1 MS Access VBA Module 1AVB201.1 MS Access VBA Module 1
AVB201.1 MS Access VBA Module 1
 
Visualbasic tutorial
Visualbasic tutorialVisualbasic tutorial
Visualbasic tutorial
 

Plus de D

Chapter 12 Human Resource Management Ppt12
Chapter 12 Human Resource Management Ppt12Chapter 12 Human Resource Management Ppt12
Chapter 12 Human Resource Management Ppt12D
 
Chapter 15 Motivating Employees Ppt15
Chapter 15 Motivating Employees Ppt15Chapter 15 Motivating Employees Ppt15
Chapter 15 Motivating Employees Ppt15D
 
Chapter 13 Understanding Individual Behavior Ppt13
Chapter 13 Understanding Individual Behavior Ppt13Chapter 13 Understanding Individual Behavior Ppt13
Chapter 13 Understanding Individual Behavior Ppt13D
 
Chapter 10 Organizational Structure And Design Ppt10
Chapter 10 Organizational Structure And Design Ppt10Chapter 10 Organizational Structure And Design Ppt10
Chapter 10 Organizational Structure And Design Ppt10D
 
Chapter 11 Communication And Information Technology Ppt11
Chapter 11 Communication And Information Technology Ppt11Chapter 11 Communication And Information Technology Ppt11
Chapter 11 Communication And Information Technology Ppt11D
 
Chapter 9 Planning Tools Techniques Ppt09
Chapter 9 Planning Tools Techniques Ppt09Chapter 9 Planning Tools Techniques Ppt09
Chapter 9 Planning Tools Techniques Ppt09D
 
Chapter 8 Strategic Management Ppt08
Chapter 8 Strategic Management Ppt08Chapter 8 Strategic Management Ppt08
Chapter 8 Strategic Management Ppt08D
 
Chapter 7 Foundations Of Planning Ppt07
Chapter 7 Foundations Of Planning Ppt07Chapter 7 Foundations Of Planning Ppt07
Chapter 7 Foundations Of Planning Ppt07D
 
Chapter 6 Decision Making The Essence Of The Managers Job Ppt06
Chapter 6 Decision Making The Essence Of The Managers Job Ppt06Chapter 6 Decision Making The Essence Of The Managers Job Ppt06
Chapter 6 Decision Making The Essence Of The Managers Job Ppt06D
 
Chapter 2 Management Yesterday And Today Ppt02
Chapter 2 Management Yesterday And Today Ppt02Chapter 2 Management Yesterday And Today Ppt02
Chapter 2 Management Yesterday And Today Ppt02D
 
Stu R C8e Ch06
Stu R C8e Ch06Stu R C8e Ch06
Stu R C8e Ch06D
 
Stu R C8e Ch15
Stu R C8e Ch15Stu R C8e Ch15
Stu R C8e Ch15D
 
Stu R C8e Ch15 11
Stu R C8e Ch15 11Stu R C8e Ch15 11
Stu R C8e Ch15 11D
 
Stu R C8e Ch 13
Stu R C8e Ch 13Stu R C8e Ch 13
Stu R C8e Ch 13D
 
Stu R C8e Ch13 12
Stu R C8e Ch13 12Stu R C8e Ch13 12
Stu R C8e Ch13 12D
 
Stu R C8e Ch12 10
Stu R C8e Ch12 10Stu R C8e Ch12 10
Stu R C8e Ch12 10D
 

Plus de D (16)

Chapter 12 Human Resource Management Ppt12
Chapter 12 Human Resource Management Ppt12Chapter 12 Human Resource Management Ppt12
Chapter 12 Human Resource Management Ppt12
 
Chapter 15 Motivating Employees Ppt15
Chapter 15 Motivating Employees Ppt15Chapter 15 Motivating Employees Ppt15
Chapter 15 Motivating Employees Ppt15
 
Chapter 13 Understanding Individual Behavior Ppt13
Chapter 13 Understanding Individual Behavior Ppt13Chapter 13 Understanding Individual Behavior Ppt13
Chapter 13 Understanding Individual Behavior Ppt13
 
Chapter 10 Organizational Structure And Design Ppt10
Chapter 10 Organizational Structure And Design Ppt10Chapter 10 Organizational Structure And Design Ppt10
Chapter 10 Organizational Structure And Design Ppt10
 
Chapter 11 Communication And Information Technology Ppt11
Chapter 11 Communication And Information Technology Ppt11Chapter 11 Communication And Information Technology Ppt11
Chapter 11 Communication And Information Technology Ppt11
 
Chapter 9 Planning Tools Techniques Ppt09
Chapter 9 Planning Tools Techniques Ppt09Chapter 9 Planning Tools Techniques Ppt09
Chapter 9 Planning Tools Techniques Ppt09
 
Chapter 8 Strategic Management Ppt08
Chapter 8 Strategic Management Ppt08Chapter 8 Strategic Management Ppt08
Chapter 8 Strategic Management Ppt08
 
Chapter 7 Foundations Of Planning Ppt07
Chapter 7 Foundations Of Planning Ppt07Chapter 7 Foundations Of Planning Ppt07
Chapter 7 Foundations Of Planning Ppt07
 
Chapter 6 Decision Making The Essence Of The Managers Job Ppt06
Chapter 6 Decision Making The Essence Of The Managers Job Ppt06Chapter 6 Decision Making The Essence Of The Managers Job Ppt06
Chapter 6 Decision Making The Essence Of The Managers Job Ppt06
 
Chapter 2 Management Yesterday And Today Ppt02
Chapter 2 Management Yesterday And Today Ppt02Chapter 2 Management Yesterday And Today Ppt02
Chapter 2 Management Yesterday And Today Ppt02
 
Stu R C8e Ch06
Stu R C8e Ch06Stu R C8e Ch06
Stu R C8e Ch06
 
Stu R C8e Ch15
Stu R C8e Ch15Stu R C8e Ch15
Stu R C8e Ch15
 
Stu R C8e Ch15 11
Stu R C8e Ch15 11Stu R C8e Ch15 11
Stu R C8e Ch15 11
 
Stu R C8e Ch 13
Stu R C8e Ch 13Stu R C8e Ch 13
Stu R C8e Ch 13
 
Stu R C8e Ch13 12
Stu R C8e Ch13 12Stu R C8e Ch13 12
Stu R C8e Ch13 12
 
Stu R C8e Ch12 10
Stu R C8e Ch12 10Stu R C8e Ch12 10
Stu R C8e Ch12 10
 

Ch07 Access

  • 1. Enhancing User Interaction Through Programming Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 1 Chapter 7 “I like thinking big. If you’re going to be thinking anything, youmight as well think big.”—Donald Trump
  • 2. Chapter Introduction Visual basic for applications (VBA) Fully customize and automate a database Perform more complex validity Use functions and actions not available with macros Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 2
  • 3. Tools Covered in This Chapter Assignment statement Breakpoints Code window DateDiff function DateSerial function Debug DoCmd statement Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 3
  • 4. Tools Covered in This Chapter (continued) If statement Immediate window Northwind sample database Variables Visual Basic editor Watches window Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 4
  • 5. Level 1 Objectives:Writing Visual Basic for Applications Code Design create and test a subroutine in a standard module Design create, and test an event procedure Analyze decisions using procedures Design create, and test a function in a standard module Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 5
  • 6. Understanding Visual Basic for Applications Programming language for Microsoft Office programs Including Access Common syntax and set of common features for all Microsoft Office programs Features unique for each Microsoft Office program Use programming language Write set of instructions to direct computer to perform specific operations in specific order Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 6
  • 7. Understanding Visual Basic for Applications (continued) Coding Statement Event-driven language Object-oriented language Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 7
  • 8. Event-Driven Programming Event State condition or occurrence that Access recognizes Has associated event property Appear in property sheet for forms reports, and controls Create group of statements using VBA code Set event property value to name of that group of statements Event procedure Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 8
  • 9. Frequently Used Access Events Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 9
  • 10. Common Events for Selected Controls Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 10
  • 11. Coding VBA Types of procedures Function procedures Performs operations Returns value Accepts input values Can be used in expressions Sub procedures Performs operations and accepts input values Does not return value Cannot be used in expressions Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 11
  • 12. Coding VBA (continued) Module Group of related procedures Starts with declarations section One or more procedures Basic types of modules Standard modules Database object stored in memory Use from anywhere in database Class modules Usually associated with particular form or report Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 12
  • 13. Coding VBA (continued) Public procedure More than one object can use Local procedure or a private procedure Only the form or report for which class module created can use event procedure Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 13
  • 14. Creating a Subroutine in a Standard Module Replace macros with VBA procedures Some tasks cannot be performed with VBA AutoKeys AutoExec Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 14
  • 15. Creating a New Standard Module Click Create tab Click Macro button arrow, and then click Module Begin new procedure in module Click Insert menu Click procedure Type name Select options Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 15
  • 16. Creating a New Standard Module (continued) Visual Basic Editor Create and modify VBA code Visual Basic window Program window that opens within VBE Code window Window to create modify and display specific VBA procedures Can have as many code windows open as modules in database Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 16
  • 17. Creating a New Standard Module (continued) Sub statement Ends with end sub statement Includes Scope of procedure Name of procedure Opening and closing parenthesis Option compare statement Designates technique access uses to compare and sort text data Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 17
  • 18. Creating a Subroutine Type statements in procedure between Sub and End Sub statements DoCmd statement Executes action in procedure Access object Method Action that operates on specific objects or controls Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 18
  • 19. Creating a Subroutine (continued) Comment Include anywhere in VBA procedure Describe what procedure or statement does Make it easier for programmers to identify purpose of statements Begin comment with Word Rem (for “remark”) Or single quotation mark (') Appear green in code window Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 19
  • 20. Creating a Subroutine (continued) Line label Statement that serves as starting point for block of statements in procedure Begins at start of line and ends with colon Underscore character at end of line Statement continues to next line Run procedure Click Run Sub/UserForm button Saves module Click Save button Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 20
  • 21. Creating an Event Procedure Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 21
  • 22. Designing an Event Procedure Associate procedure with form’s On Current event property Triggered when form’s Current event occurs Occurs when focus moves to record Add event procedure Open property sheet for form Click On Current text box Click list arrow Click [event procedure] Click Build button to right of On Current text box Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 22
  • 23. Making Decisions Using the If Statement Decision-making statement Executes group of statements based on outcome of condition Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 23
  • 24. Making Decisions Using the If Statement (continued) If statement Tests condition follows one of two paths depending on outcome of condition General form If condition Then True-statement group [Else False-statement group] End If Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 24
  • 25. Making Decisions Using the If Statement (continued) Assignment statement Assigns value of expression to control or property Example EstSalary.ForeColor = vbGreen ForeColor property Color constants Predefined VBA names Have values that represent system color value IsNull functions returns True value when field or control null False when not Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 25
  • 26. Comparison Operators and How to Use Them in Conditions Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 26
  • 27. Testing an Event Procedure Switch to form view Navigate through records Make sure results correct in different situations Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 27
  • 28. Creating a Function Similar calculation requests Create function to perform calculation Function Begins with Function statement Ends with End Function statement Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 28
  • 29. Variables Named location in computer memory Can contain value Use to store and retrieve data Reference using variable name assigned to location Holds only one value at a time Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 29
  • 30. Variables (continued) Naming rules Must begin with letter Cannot exceed 255 characters Include letters numbers and underscore character Cannot use space, punctuation, or special characters Cannot be same as keywords or reserved words Each variable has data type Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 30
  • 31. Common VBA Data Types Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 31
  • 32. Using Functions Similar to way built-in functions used Call a function Function name followed by argument(s) Commas separate multiple arguments DateDiff function Calculates number of time intervals between two dates Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 32
  • 33. Testing a Function in the Immediate Window When statement entered Editor checks statement to make sure syntax correct Logic error Occurs when procedure produces incorrect results Immediate window Test VBA procedures without changing data in database Enter different values to test procedure Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 33
  • 34. Testing a Function in the Immediate Window (continued) Immediate window Type keyword “print” or question mark (?) Followed by procedure name and argument values to test in parentheses and separated by commas DateSerial function Returns date value for specified year, month, and day Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 34
  • 35. Level 1 Summary VBA Programming language for Microsoft Office programs Create procedures in module Event-driven programming Program statement execution triggered by events If statement Used to make decisions Function Returns a value Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 35
  • 36. Level 2 Objectives:Using Custom Functions and Verifying Data Design create and test a custom function in an event procedure Use ElseIf and If statements Verify data using event procedures Use the Case control structure Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 36
  • 37. Enhancing an Event Procedure to Use a Custom Function Add and change statements in a procedure Open object that contains event procedure in Design view Click View Code button on Design Ribbon Add new procedure module or class module Click Insert on menu bar Click Procedure, Module, or Class Module Edit existing statements Scroll code window to desired statement Make necessary changes Press Save button on Visual Basic toolbar Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 37
  • 38. Using an ElseIf Statement in an If Statement Date function Returns current computer system date ElseIf statement Equivalent to Else clause followed by If statement Choice of which If statement version used Matter of personal preference Arranging order of condition testing Order of condition testing critical Place conditions in order from least inclusive to most inclusive Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 38
  • 39. Comparing an ElseIf Clause to an Else…if Clause Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 39
  • 40. Using an ElseIf Statement in an if Statement (continued) Dim statement Declare variables and associated data types in procedure Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 40
  • 41. Verifying Data with VBA Before Update event Occurs before changed data in control or record updated in database Use to verify entered data Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 41
  • 42. Designing the Field Validation Procedure to Verify Zip Codes Cancel As Integer Defines Cancel as parameter with Integer data type For some events access executes attached event procedure before performing default behavior Can cancel default behavior in event procedure or macro Using Cancel parameter Left function Returns string containing specified number of characters from left side of specified string Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 42
  • 43. Designing the Field Validation Procedure to Verify Zip Codes (continued) Val function Returns numbers contained in specified string as numeric value Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 43
  • 44. Using the Case Control Structure Control structure Set of VBA statements work together as a unit Case control structure Evaluates expression Performs one of several alternative sets of statements Based on resulting value (or condition) of evaluated expression Use Case Else statement as last Case statement Include false-statement group Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 44
  • 45. Using the Case Control Structure (continued) CancelEvent action Cancels event that caused procedure or macro containing action to execute Me keyword Refers to current object Undo Method that clears all changes made to current record SetFocus Moves focus to specified object or control Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 45
  • 46. Testing the Field Validation Procedure to Verify Zip Codes Switch to form view to test validation procedure Using event procedure for control or form Before Update event for each control on form Need two or more fields as part of validation process Use form’s Before Update event Disadvantage All changes made to record undone Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 46
  • 47. Designing the Field Validation Procedure to Verify Phone Area Codes Message can suggest potential error Must accept any phone area code entry Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 47
  • 48. Level 2 Summary ElseIf statement Verify data using VBA Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 48
  • 49. Level 3 Objectives: Testing and Exploring VBA Troubleshoot problems in VBA procedures Compile modules Develop sources for learning VBA Explore completed modules in the Northwind sample database Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 49
  • 50. Troubleshooting VBA Procedures Syntax error Occurs when VBA statement violates language rules for statement such as Misspelling Incorrect sequence of keywords Missing parenthesis Detected immediately when statement completed Error message opens and explains error Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 50
  • 51. Syntax Error Message Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 51
  • 52. Troubleshooting VBA Procedures (continued) Compilation error Occurs when procedures translated into form computer can understand Compilation Process of translating modules from VBA to form computer understands Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 52
  • 53. Troubleshooting VBA Procedures (continued) Prevent compilation errors at run time Use Compile command on Debug menu Compile as last step before saving module Execution error or run-time error Occurs when procedure executes and stops because it tries to perform operation that is impossible to perform Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 53
  • 54. Using the Debugger to Correct Errors Breakpoint Run subroutine or function up until line on which breakpoint set Procedure halts execution at point and displays module screen Good way to isolate place at which procedure stops producing anticipated result Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 54
  • 55. Using the Debugger to Correct Errors (continued) Use mouse pointer to get more information about procedure Pointing to variable name displays ScreenTip with value contained in variable at point that procedure halted Execute procedure one statement at a time Try and identify cause of error Click Debug on menu bar Click Step Into Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 55
  • 56. Using the Debugger to Correct Errors (continued) Step Into Procedure executes next statement and stops Step Out Executes current subroutine or function and then halts Reset button Stops debugger so you can fix problem Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 56
  • 57. Identifying Errors Using the Watches Window Watches window Shows current value of specified variable Add Watch dialog box Enter variable name to watch “<Out of context>” in value column Appears for watch expression When access not executing procedure that contains watch expression Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 57
  • 58. Add Watch Dialog Box Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 58
  • 59. Building Procedures Slowly to Isolate Problems Prevent problems in procedures Build them slowly using small groups of statements Prove them to be correct as you go Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 59
  • 60. Using Help to Learn More About Programming and VBA Access Help contains valuable information about VBA Reading individual topics gives excellent background Search results list Sample code for situations Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 60
  • 61. Visual Basic Help Table Of Contents Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 61
  • 62. Level 3 Summary Errors Syntax Compilation Execution or run-time Debugger Use to find and correct errors Help Learn more about VBA Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 62
  • 63. Chapter Summary VBA Programming language for Microsoft Office applications Decision structures If ElseIf Case Develop subroutines Use debugger to find errors Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 63