xp chapter 7 succeeding in business with microsoft office access 2003: a problem-solving approach 1...

67
Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 XP Enhancing User Interaction Through Programming Chapter 7 “I like thinking big. If you’re going to be thinking anything, you might as well think big.” —Donald Trump

Upload: gregory-barber

Post on 11-Jan-2016

214 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: XP Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Enhancing User Interaction Through Programming Chapter

Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach

1

XP

Enhancing User Interaction Through Programming

Chapter 7

“I like thinking big. If you’re going to be thinking anything, youmight as well think big.”

—Donald Trump

Page 2: XP Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Enhancing User Interaction Through Programming Chapter

Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach

2

XPChapter Introduction

• Visual basic for applications (VBA) Fully customize and automate a database Perform more complex validity Use functions and actions not available with macros

Page 3: XP Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Enhancing User Interaction Through Programming Chapter

Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach

3

XPTools Covered in This Chapter

• Assignment statement

• Breakpoints

• Code window

• DateDiff function

• DateSerial function

• Debug

• DoCmd statement

Page 4: XP Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Enhancing User Interaction Through Programming Chapter

Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach

4

XPTools Covered in This Chapter (continued)

• If statement

• Immediate window

• Northwind sample database

• Variables

• Visual basic editor

• Watches window

Page 5: XP Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Enhancing User Interaction Through Programming Chapter

Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach

5

XPLevel 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

Page 6: XP Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Enhancing User Interaction Through Programming Chapter

Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach

6

XPUnderstanding 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

Page 7: XP Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Enhancing User Interaction Through Programming Chapter

Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach

7

XPUnderstanding Visual Basic for Applications (continued)

• Coding

• Statement

• Event-driven language

• Object-oriented language

Page 8: XP Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Enhancing User Interaction Through Programming Chapter

Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach

8

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

Page 9: XP Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Enhancing User Interaction Through Programming Chapter

Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach

9

XPFrequently Used Access Events

Page 10: XP Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Enhancing User Interaction Through Programming Chapter

Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach

10

XPFrequently Used Access Events (continued)

Page 11: XP Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Enhancing User Interaction Through Programming Chapter

Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach

11

XPCommon Events for Selected Controls

Page 12: XP Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Enhancing User Interaction Through Programming Chapter

Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach

12

XPCoding 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

Page 13: XP Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Enhancing User Interaction Through Programming Chapter

Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach

13

XPCoding 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

Page 14: XP Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Enhancing User Interaction Through Programming Chapter

Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach

14

XPCoding 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

Page 15: XP Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Enhancing User Interaction Through Programming Chapter

Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach

15

XPCreating a Subroutine in a Standard Module

• Replace macros with VBA procedures Some tasks cannot be performed with VBA

• AutoKeys• AutoExec

Page 16: XP Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Enhancing User Interaction Through Programming Chapter

Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach

16

XPCreating a New Standard Module

• Click modules tab Click new button

• Begin new procedure in module Click list arrow on insert module button Click procedure Type name Select options

Page 17: XP Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Enhancing User Interaction Through Programming Chapter

Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach

17

XPCreating 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

Page 18: XP Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Enhancing User Interaction Through Programming Chapter

Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach

18

XPCreating 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

Page 19: XP Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Enhancing User Interaction Through Programming Chapter

Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach

19

XPCreating 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

Page 20: XP Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Enhancing User Interaction Through Programming Chapter

Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach

20

XPCreating 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

Page 21: XP Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Enhancing User Interaction Through Programming Chapter

Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach

21

XPCreating 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

Page 22: XP Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Enhancing User Interaction Through Programming Chapter

Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach

22

XPCreating an Event Procedure

Page 23: XP Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Enhancing User Interaction Through Programming Chapter

Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach

23

XPDesigning 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

Page 24: XP Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Enhancing User Interaction Through Programming Chapter

Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach

24

XPMaking Decisions Using the If Statement

• Decision-making statement Executes group of statements based on outcome of

condition

Page 25: XP Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Enhancing User Interaction Through Programming Chapter

Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach

25

XPMaking 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

Page 26: XP Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Enhancing User Interaction Through Programming Chapter

Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach

26

XPMaking 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

Page 27: XP Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Enhancing User Interaction Through Programming Chapter

Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach

27

XPComparison Operators and How to Use Them in Conditions

Page 28: XP Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Enhancing User Interaction Through Programming Chapter

Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach

28

XPMaking Decisions Using the If Statement (continued)

• IsNull function returns True value when field or control null False when not

Page 29: XP Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Enhancing User Interaction Through Programming Chapter

Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach

29

XPTesting an Event Procedure

• Switch to form view

• Navigate through records Make sure results correct in different situations

Page 30: XP Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Enhancing User Interaction Through Programming Chapter

Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach

30

XPCreating a Function

• Similar calculation requests Create function to perform calculation

• Function Begins with Function statement Ends with End Function statement

Page 31: XP Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Enhancing User Interaction Through Programming Chapter

Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach

31

XPVariables

• 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

Page 32: XP Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Enhancing User Interaction Through Programming Chapter

Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach

32

XPVariables (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

Page 33: XP Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Enhancing User Interaction Through Programming Chapter

Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach

33

XPCommon VBA Data Types

Page 34: XP Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Enhancing User Interaction Through Programming Chapter

Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach

34

XPUsing Functions

• Similar to way built-in functions used

• Call function Function name followed by argument(s) Commas separate multiple arguments

• DateDiff function Calculates number of time intervals between two dates

Page 35: XP Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Enhancing User Interaction Through Programming Chapter

Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach

35

XPTesting 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

Page 36: XP Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Enhancing User Interaction Through Programming Chapter

Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach

36

XPTesting 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

Page 37: XP Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Enhancing User Interaction Through Programming Chapter

Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach

37

XPLevel 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

Page 38: XP Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Enhancing User Interaction Through Programming Chapter

Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach

38

XPLevel 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

Page 39: XP Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Enhancing User Interaction Through Programming Chapter

Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach

39

XPEnhancing 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 Code button on toolbar 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 Standard toolbar

Page 40: XP Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Enhancing User Interaction Through Programming Chapter

Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach

40

XPUsing 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

Page 41: XP Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Enhancing User Interaction Through Programming Chapter

Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach

41

XPComparing an ElseIf Clause to an Else…if Clause

Page 42: XP Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Enhancing User Interaction Through Programming Chapter

Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach

42

XPUsing an ElseIf Statement in an if Statement (continued)

• Dim statement Declare variables and associated data types in

procedure

Page 43: XP Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Enhancing User Interaction Through Programming Chapter

Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach

43

XPVerifying Data with VBA

• Before Update event Occurs before changed data in control or record

updated in database Use to verify entered data

Page 44: XP Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Enhancing User Interaction Through Programming Chapter

Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach

44

XPDesigning 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

Page 45: XP Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Enhancing User Interaction Through Programming Chapter

Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach

45

XPDesigning the Field Validation Procedure to Verify Zip Codes

(continued)

• Val function Returns numbers contained in specified string as

numeric value

Page 46: XP Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Enhancing User Interaction Through Programming Chapter

Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach

46

XPUsing 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

Page 47: XP Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Enhancing User Interaction Through Programming Chapter

Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach

47

XPUsing 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

Page 48: XP Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Enhancing User Interaction Through Programming Chapter

Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach

48

XPTesting 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

Page 49: XP Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Enhancing User Interaction Through Programming Chapter

Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach

49

XPDesigning the Field Validation Procedure to Verify Phone Area

Codes

• Message can suggest potential error Must accept any phone area code entry

Page 50: XP Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Enhancing User Interaction Through Programming Chapter

Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach

50

XPLevel 2 Summary

• ElseIf statement

• Verify data using VBA

Page 51: XP Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Enhancing User Interaction Through Programming Chapter

Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach

51

XPLevel 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

Page 52: XP Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Enhancing User Interaction Through Programming Chapter

Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach

52

XPTroubleshooting 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

Page 53: XP Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Enhancing User Interaction Through Programming Chapter

Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach

53

XPSyntax Error Message

Page 54: XP Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Enhancing User Interaction Through Programming Chapter

Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach

54

XPTroubleshooting 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

Page 55: XP Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Enhancing User Interaction Through Programming Chapter

Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach

55

XPTroubleshooting 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

Page 56: XP Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Enhancing User Interaction Through Programming Chapter

Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach

56

XPUsing 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

Page 57: XP Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Enhancing User Interaction Through Programming Chapter

Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach

57

XPUsing 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

Page 58: XP Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Enhancing User Interaction Through Programming Chapter

Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach

58

XPUsing 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

Page 59: XP Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Enhancing User Interaction Through Programming Chapter

Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach

59

XPIdentifying 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

Page 60: XP Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Enhancing User Interaction Through Programming Chapter

Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach

60

XPAdd Watch Dialog Box

Page 61: XP Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Enhancing User Interaction Through Programming Chapter

Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach

61

XPBuilding 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

Page 62: XP Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Enhancing User Interaction Through Programming Chapter

Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach

62

XPExploring VBA

• Powerful but complicated language

• Takes time to learn

• Know what resources available

Page 63: XP Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Enhancing User Interaction Through Programming Chapter

Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach

63

XPUsing the Northwind Sample Database

• Very efficient to reuse code included in different modules

• Sample Northwind database Installed with access Study existing procedures Load by clicking help on menu bar in access

• Point to sample databases• Click Northwind sample database

Contains variety of simple and complex VBA procedures

Page 64: XP Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Enhancing User Interaction Through Programming Chapter

Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach

64

XPUsing 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

Page 65: XP Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Enhancing User Interaction Through Programming Chapter

Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach

65

XPVisual Basic Help Table Of Contents

Page 66: XP Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Enhancing User Interaction Through Programming Chapter

Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach

66

XPLevel 3 Summary

• Errors Syntax Compilation Execution or run-time

• Debugger Use to find and correct errors

• Help Learn more about VBA

Page 67: XP Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Enhancing User Interaction Through Programming Chapter

Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach

67

XPChapter Summary

• VBA Programming language for Microsoft Office

applications

• Decision structures If ElseIf Case

• Develop subroutines

• Use debugger to find errors