1. 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
2. Chapter 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
3. Tools 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
4. Level 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
5. Understanding 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
6. Understanding 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
7. Typical Switchboard Design Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 7
8. Designing 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
9. Creating 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
10. Switchboard Manager Buttons Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 10
11. Edit Switchboard Item Dialog Box Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 11
13. Formatting 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
14. Understanding 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
15. Common Macro Actions Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 15
16. Creating 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
17. Creating 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
18. Running 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
19. Macro Design Toolbar Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 19
20. Editing 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
21. Setting 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
22. Specifying 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
23. Startup Dialog Box Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 23
24. Creating 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
25. Creating 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
26. Creating 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
27. Level 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
28. Level 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
29. Understanding 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
30. Creating 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
31. Running 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
32. Running 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
33. Creating 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
34. Examples of Key Combinations for the Autokeys Macro Group Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 34
35. Modifying 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
36. Specifying 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
37. Assigning 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
38. Specifying 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
39. Troubleshooting 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
40. Printing 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
41. Single 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
42. Using 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
43. Using 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
44. Level 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
45. Level 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
46. Exploring 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
47. Exploring 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
48. Exploring 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
49. Assigning 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
50. Report Events Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 50
51. Report Section Events Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 51
52. Using 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
53. Form Events Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 53
54. Using 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
55. Using 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
56. Using 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
57. Validating 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
58. Common Domain Aggregate Functions Succeeding in Business with Microsoft Office Access 2007: A Problem-Solving Approach 58
59. Level 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
60. Chapter 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