Access Lesson 11 Creating and Running Macros Microsoft Office 2010 Advanced Cable / Morrison 1
Access Lesson 11 Cable / MorrisonMicrosoft Office 2010 Advanced Objectives Review macro security settings. Record a macro. Run a macro. Edit a macro. 222
Access Lesson 11 Cable / MorrisonMicrosoft Office 2010 Advanced Objectives (continued) Create a macro to open and print reports. Run a macro with multiple actions. Create an embedded macro. View and run an embedded macro. 333
Access Lesson 11 Cable / MorrisonMicrosoft Office 2010 Advanced Vocabulary argument code comment embedded macro filter macro run virus 444
Access Lesson 11 Cable / MorrisonMicrosoft Office 2010 Advanced Introduction A macro automates common, repetitive tasks you perform in Access. – Saves valuable time In this lesson, students will learn: – About macros and potential viruses – How to create and run macros – How to make changes to a macro – How to add a macro to a button that can be clicked to run the macro 5
Access Lesson 11 Cable / MorrisonMicrosoft Office 2010 Advanced Understanding Macros A macro is a series of actions that you want Access to perform. Visual Basic for Applications (or VBA) is the program used to create macros. When a macro is being recorded, all of the selections you make are translated into code. Code is simply the macro actions formatted in easy-to-read sentences. 6
Access Lesson 11 Cable / MorrisonMicrosoft Office 2010 Advanced Reviewing Macro Security Settings Macros are susceptible to virus attacks. A virus is a computer program that is designed to reproduce itself by attaching to other programs in a computer. To help protect against a virus hidden in a macro, you can set one of four macro security levels in Access. 7
Access Lesson 11 Cable / MorrisonMicrosoft Office 2010 Advanced Reviewing Macro Security Settings (continued) Macro security level options 8
Access Lesson 11 Cable / MorrisonMicrosoft Office 2010 Advanced Creating a Macro You create an Access macro in the Macro window. In the Macro window, you select actions. – Actions perform tasks, such as opening a form. You can select an action using one of several methods. Arguments are the additional information that Access needs based on the chosen action. 9
Access Lesson 11 Cable / MorrisonMicrosoft Office 2010 Advanced Creating a Macro (continued) Macro window for creating macros 10
Access Lesson 11 Cable / MorrisonMicrosoft Office 2010 Advanced Creating a Macro (continued) Macro window with completed macro 11
Access Lesson 11 Cable / MorrisonMicrosoft Office 2010 Advanced Running a Macro You can run a macro in three ways: – In the Navigation pane, right-click the macro name, and then click Run on the shortcut menu. – On the Database Tools tab, click the Run Macro button in the Macro group, select the macro in the Run Macro dialog box, and then click OK. – On the Macro Tools Design tab, click the Run button in the Tools group. 12
Access Lesson 11 Cable / MorrisonMicrosoft Office 2010 Advanced Editing a Macro You use the Macro window to edit a macro. A comment is explanatory text that you can add to a macro that does not affect the way the macro is executed. A filter displays only certain records based on certain criteria. 13
Access Lesson 11 Cable / MorrisonMicrosoft Office 2010 Advanced Editing a Macro (continued) Comment shown above action 14
Access Lesson 11 Cable / MorrisonMicrosoft Office 2010 Advanced Creating a Macro to Open and Print Reports When you record a macro, you can include multiple actions in it. – For example, you can create a macro to open, print, and close a form The actions should be entered in a logical order. 15
Access Lesson 11 Cable / MorrisonMicrosoft Office 2010 Advanced Creating a Macro to Open and Print Reports (continued) Macro window with three actions 16
Access Lesson 11 Cable / MorrisonMicrosoft Office 2010 Advanced Running a Macro with Multiple Actions It is always a good idea to run a macro after you complete it to be certain that it performs the tasks you chose. If there is a problem, you can edit the macro. 17
Access Lesson 11 Cable / MorrisonMicrosoft Office 2010 Advanced Creating an Embedded Macro An embedded macro is a macro that performs an action within an object. – Such as, a macro that opens a form when you are already viewing another form An embedded macro can be part of another object, such as a command button. Embedded macros have events that run the macro, such as On Click. 18
Access Lesson 11 Cable / MorrisonMicrosoft Office 2010 Advanced Creating an Embedded Macro (continued) Form events 19
Access Lesson 11 Cable / MorrisonMicrosoft Office 2010 Advanced Viewing and Running the Embedded Macro When you create a command button with an embedded macro, you can view the event and the embedded macro using the Property Sheet. To run the macro, click on the command button. 20
Access Lesson 11 Cable / MorrisonMicrosoft Office 2010 Advanced Viewing and Running the Embedded Macro (continued) Property Sheet for command button 21
Access Lesson 11 Cable / MorrisonMicrosoft Office 2010 Advanced Summary In this lesson, you learned: You can view and change macro security settings. Recording a macro can save you time for repetitive tasks. Running a macro performs the tasks that were recorded. Macros can be edited after they are created. 22
Access Lesson 11 Cable / MorrisonMicrosoft Office 2010 Advanced Summary (continued) You can create a macro that opens and prints multiple reports. When you run a macro with multiple actions, the actions are performed based on their order in the macro. An embedded macro is a macro that can be part of a command button in a form. 23
Access Lesson 11 Cable / MorrisonMicrosoft Office 2010 Advanced Summary (continued) When you view an embedded macro, it appears in the macro window, and you can run the macro by clicking the command button. 24