+ All Categories
Home > Documents > Ch06 Access

Ch06 Access

Date post: 09-May-2015
Category:
Upload: d
View: 1,725 times
Download: 0 times
Share this document with a friend
60
Automating Database Processing Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 1 Chapter 6 “An organization’s ability to learn, and translate that learning into action rapidly, is the ultimate competitive advantage.” —Jack Welch
Transcript
Page 1: Ch06 Access

Automating Database Processing

Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 1

Chapter 6

“An organization’s ability to learn, and translate that learninginto action rapidly, is the ultimate competitive advantage.”

—Jack Welch

Page 2: Ch06 Access

XPXPChapter Introduction• Design and implement user-friendly menu

– Called switchboard• Macros

– Automate repetitive tasks– Conditions

Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 2

Page 3: Ch06 Access

XPXPTools Covered in This Chapter• AutoExec macro• AutoKeys macro• Macro window• Startup dialog box• Switchboard Manager

Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 3

Page 4: Ch06 Access

XPXPLevel 1 Objectives: Automating Tasks with Switchboards and Macros• Create a well-designed switchboard to provide a

user interface for a database• Automate tasks by creating basic macros• Specify what happens when a database opens

Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 4

Page 5: Ch06 Access

XPXPUnderstanding Switchboards• Switchboard

– Special kind of form – Appears when database opened– Lists options for working with database objects

• Select up to eight objects to list on switchboard• Determine what action Access should take when

users select option

Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 5

Page 6: Ch06 Access

XPXPUnderstanding Switchboards (continued)• Typical switchboard buttons

– Open forms reports and other objects – Open other switchboards that list additional database

objects – Close switchboard– Open the Navigation Pane– Close Access

• Main switchboard– Large number of database objects– Launches other switchboards

Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 6

Page 7: Ch06 Access

XPXPTypical Switchboard Design

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

Page 8: Ch06 Access

XPXPDesigning a Switchboard• Switchboard Manager

– Tool to design and customize switchboard– Create main switchboard– Add buttons– Specify button properties– Access creates switchboard form

• Only one switchboard per database– Can contain many pages

Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 8

Page 9: Ch06 Access

XPXPCreating a Switchboard • Open Switchboard Manager

– Switchboard Manager dialog box– Use five buttons on Switchboard Manager dialog box to

perform tasks

• Create secondary switchboards first• Verify new form creation• Switchboard item table

– Keeps track of switchboard items commands and arguments – Should be altered only through Switchboard Manager

Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 9

Page 10: Ch06 Access

XPXPSwitchboard Manager Buttons

Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 10

Page 11: Ch06 Access

XPXPEdit Switchboard Item Dialog Box

Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 11

Page 12: Ch06 Access

XPXPSwitchboard Commands

Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 12

Page 13: Ch06 Access

XPXPFormatting a Switchboard• By default Access switchboards share same

layout and design – Including background colors and placement of title

• Switchboard Manager doesn’t provide options for modifying switchboard design– Format switchboard in form design view– Do not change command buttons or properties

Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 13

Page 14: Ch06 Access

XPXPUnderstanding Basic Macros• Macro

– Action or series of actions – Save time and ensure accuracy– Usually assigned to key, key combination, or button– Composed of series of actions organized in sequence

in which they should be performed• Create macro

– Using Macro window

Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 14

Page 15: Ch06 Access

XPXPCommon Macro Actions

Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 15

Page 16: Ch06 Access

XPXPCreating a Macro• Create Access macro in Macro window• Select the Create tab, and then click the Macro

button in the Other group• Action column

– List actions macro performs– Click list arrow in action column– Access provides over 50 different actions

• Comment column– Document action by describing what task it performs

Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 16

Page 17: Ch06 Access

XPXPCreating a Macro (continued)• Action arguments pane

– Provide additional information for performing macro action

– Arguments needed vary depending on selected action chosen

Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 17

Page 18: Ch06 Access

XPXPRunning a Macro• In Macro window

– Click the Run button in the Design tab

• Click Run Macro on the Database Tools Ribbon, click the list arrow and select the macro, and then click OK

• In the Navigation Pane, click Macros, right-click the macro name, and then click Run

Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 18

Page 19: Ch06 Access

XPXPMacro Design Toolbar

Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 19

Page 20: Ch06 Access

XPXPEditing a Macro• Use Macro window• Rearrange order of actions

– Drag action line to new position• Insert new action between two existing actions

– Right-click row – Click insert rows

• Delete action– Right-click row – Click delete rows

Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 20

Page 21: Ch06 Access

XPXPSetting Startup Options• Startup options

– Access performs when database opens• Use Startup dialog box• Bypass Startup Options

– Press and hold down shift key when opening database

Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 21

Page 22: Ch06 Access

XPXPSpecifying Startup Options in the Startup Dialog Box• Options

– Display form– Display navigation pane– Allow full menus

Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 22

Page 23: Ch06 Access

XPXPStartup Dialog Box

Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 23

Page 24: Ch06 Access

XPXPCreating a Splash Screen• Splash screen

– Displays when database opens– Contains

• Logo• Text

• Can only display splash screen or switchboard automatically

Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 24

Page 25: Ch06 Access

XPXPCreating a Splash Screen (continued)• AutoExec

– Special macro– Runs when database opens– Before startup dialog box options– Can use to display splash screen

• Create splash screen form

Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 25

Page 26: Ch06 Access

XPXPCreating an AutoExec Macro• Create macro that contains actions Access should

perform when database opened• Save macro using name AutoExec

Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 26

Page 27: Ch06 Access

XPXPLevel 1 Summary• Switchboard

– Special kind of form – Appears when database opened

• Macro– Use to automate repeated actions

• Startup options dialog box• Splash screen

Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 27

Page 28: Ch06 Access

XPXPLevel 2 Objectives:Creating Advanced Macros• Consolidate automated tasks by creating a macro

group• Create buttons that can perform a series of

actions• Troubleshoot macros

Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 28

Page 29: Ch06 Access

XPXPUnderstanding Macro Groups• Macro group

– Two or more macros placed within same macro file– Consolidate related macros – Manage large numbers of macros– Only group name displayed as macro object in

database window

Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 29

Page 30: Ch06 Access

XPXPCreating a Macro Group• Logical to organize similar macros within group

– To create Click the Create tab and then click the Macro button– Click the Macro Names button on the Design tab. Access adds

the Macro Name column to the left of the Action column– In the Macro Name column, enter the name of a macro– In the Action column, enter the corresponding actions for the

macro– Enter comments as needed in the Comment column, and set

arguments as needed in the Action Arguments pane– Save the macro group, using the “mcr” prefix in the object

name

Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 30

Page 31: Ch06 Access

XPXPRunning the Macros in a Macro Group• Run particular macro within group

– Click the Run Macro button in the Macro group on the Database Tools Ribbon

– Select the list arrow to choose the macro name– Click the macro name– Click OK

• Switchboard Manager and many property sheets– Specify name of macro to run

Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 31

Page 32: Ch06 Access

XPXPRunning the Macros in a Macro Group• Run macro object

– Enter or select name– Run only one macro in macro group

• Use special notation mcrGroupName.mcrMacroName

Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 32

Page 33: Ch06 Access

XPXPCreating an AutoKeys Macro Group• AutoKeys macro group

– Assign macro action or set of actions to key or key combination

– Macro name column• Type key or key combination • Use special syntax

• SendKeys action – Sends keystrokes to Access or to another active

program

Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 33

Page 34: Ch06 Access

XPXPExamples of Key Combinations for the Autokeys Macro Group

Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 34

Page 35: Ch06 Access

XPXPModifying the Switchboard to Run Macros• Modify switchboard to include

– Macro group listing macros that open queries

Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 35

Page 36: Ch06 Access

XPXPSpecifying Conditions and Events for Macros• Specify conditions for performing macro actions • Assign macro to control• Event-driven programming

– Running macro when user interacts with object• Event

– State condition or occurrence that Access recognizes• Event property

– Specifies how object responds when event occurs– Set to macro name to run macro when even occurs

Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 36

Page 37: Ch06 Access

XPXPAssigning a Macro to a Control• Create macro or macro group that performs

series of actions• Assign macro to control

– Add command button to form by opening form in Design view

– Attach macro with desired actions to command button

• Using On Click property

Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 37

Page 38: Ch06 Access

XPXPSpecifying Conditions in a Macro• Where condition argument• Refer to controls on form that are not currently

active– Use control’s complete name– Format

• [Forms]![formName]![controlName]

Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 38

Page 39: Ch06 Access

XPXPTroubleshooting Macros• Macros containing arguments

– Especially error prone• Error types

– Syntax error– Logic error– Run-time error

• Troubleshooting tools– Single step through execution of macro, using debug

window– Print macro code

Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 39

Page 40: Ch06 Access

XPXPPrinting Macros• Open Documenter dialog box

– Select macro– Click options button to select details of macro to print

Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 40

Page 41: Ch06 Access

XPXPSingle Stepping a Macro• Runs macro one action at time

– Pausing between actions• Make sure actions appear in correct order and

with correct arguments• Use Single Step button

– Macro Single Step dialog box– Buttons

• Step• Halt• Continue

Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 41

Page 42: Ch06 Access

XPXPUsing Breakpoints and the Debug Window• Breakpoint

– Code inserted in macro– Signals where to stop macro

• Examine values of actions controls, and arguments macro using in debug window

• Debug window – Shows macro as it appears in VBA code– Examine details of macro code in debug window

Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 42

Page 43: Ch06 Access

XPXPUsing Breakpoints and the Debug Window (continued)• Immediate pane

– Displays current value of controls and arguments– Display using ? operator

Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 43

Page 44: Ch06 Access

XPXPLevel 2 Summary• Macro group• Conditions for macros• Assign macro to control• Debug macros

Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 44

Page 45: Ch06 Access

XPXPLevel 3 Objectives:Macro Conditions• Display message boxes under specified

conditions• Run a macro when a form opens or a report

prints• Use a macro to validate data

Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 45

Page 46: Ch06 Access

XPXPExploring Macro Conditions• Macro conditions

– Logical expressions that result in true or false answer– Depending on outcome

• Macro can perform one set of actions or another

• Enter macro conditions – Open condition column in Macro window

• By clicking Conditions button

• If condition true – Access performs corresponding action in action

column

Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 46

Page 47: Ch06 Access

XPXPExploring Macro Conditions• Perform more than one action if condition true

– Enter conditional statement in condition column – Select actions in action column in order – Enter ellipsis (…) for each subsequent action

associated with condition in condition column

Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 47

Page 48: Ch06 Access

XPXPExploring Macro Conditions (continued)• SetValue action

– Change property of object by disabling, updating, hiding, or displaying control

– Arguments • Item• Expression

Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 48

Page 49: Ch06 Access

XPXPAssigning a Macro to an Object Event• Assign macro to object

– By specifying macro name in event property of object• Event categories

– Report– Section

Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 49

Page 50: Ch06 Access

XPXPReport Events

Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 50

Page 51: Ch06 Access

XPXPReport Section Events

Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 51

Page 52: Ch06 Access

XPXPUsing Message Boxes with Forms• Form events can also trigger macros• Use to

– Validate data – Set values – Navigate between forms– Filter, find, and print records

Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 52

Page 53: Ch06 Access

XPXPForm Events

Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 53

Page 54: Ch06 Access

XPXPUsing Message Boxes with Forms• MsgBox command

– Opens message box – Displays warning or informational message– MsgBox ("message" sum of button and icon values "title")

– Returns value depending on which button clicked– Create condition that checks to see which button

users click

Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 54

Page 55: Ch06 Access

XPXPUsing Message Boxes with Reports• When conditions in macro references name of

control from source – Source must be open when condition tested– Can hide window while macro tests condition

• MsgBox action– Opens message box and displays warning or

informational message– Similar to using MsgBox command

Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 55

Page 56: Ch06 Access

XPXPUsing Message Boxes with Reports (continued)• MsgBox action arguments

– Message – Beep – Type– Title

Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 56

Page 57: Ch06 Access

XPXPValidating Data with Macros• Validation field properties have limits• Validate data using more than one rule and more

than one validation message– Create macro

• Domain aggregate functions– Calculate statistics for set of records (recordset) or

domain, from table or query• Dcount function

– Dcount(expression, table or query, condition)

Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 57

Page 58: Ch06 Access

XPXPCommon Domain Aggregate Functions

Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 58

Page 59: Ch06 Access

XPXPLevel 3 Summary• Conditional expressions in macros• Assign macros to events• Message boxes

– Msgbox command– Msgbox action

• Validate data with macros

Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 59

Page 60: Ch06 Access

XPXPChapter Summary• Switchboard

– Provides main menu for Access application• Macro

– Automates repetitive tasks– Can use conditional expressions– Associate with command buttons or other controls

• Debugger– Find errors in macros by stepping though each

statement

Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 60


Recommended