160 likes | 486 Views
Access Macros. ISYS 562. Why Use Macro? . In Microsoft Access, you can accomplish many tasks by using macros. Macros are an easy way to take care of simple details such as opening and closing forms and running reports because there's little syntax to remember. . To create a macro.
E N D
Access Macros ISYS 562
Why Use Macro? • In Microsoft Access, you can accomplish many tasks by using macros. Macros are an easy way to take care of simple details such as opening and closing forms and running reports because there's little syntax to remember.
To create a macro • In the database windows, click Macros/New • Add an action to the macro. • In the lower part of the window, specify arguments for the action, if any are required. • To add more actions to the macro, move to another action row and add action. • Microsoft Access carries out the actions in the order you list them.
Macro’s Actions • OpenForm, OpenReport • TransferDatabase, TransferSpreadsheet • OutputTo • CopyDatabaseFile, CopyObject • FindNext, FindRecord • RunCode, RunCommand, RunSQL, RunApp, RunMacro • SendObject • SetValue
Macro Condition • You can use any expression that evaluates to True/False or Yes/No in a macro condition. The macro will be executed if the condition evaluates to True. • Example: [Forms]![employee]![empID]="E1" • To add a condition: • At macro design view: • View/Condition
Macro Group and Macro Name • Macro group is collection of related macros that are stored together under a single macro name. • To create a macro group (name): • Click the macro name button or right-click macro window’s title. • In the Macro Name column, type a name for the first macro in the macro group and add the action you want the macro to carry out. • Add other macros you want to include in the macro group.
How a Macro Group Runs • When you run a macro group, Microsoft Access executes each macro, starting from the first action, until it encounters a StopMacro action, another macro group name, or no further actions. • When you save the macro group, the name you specify is the name of the group of macros. This name is displayed in the list of macros and macro groups in the Database window. Whenever you refer to a macro in a macro group, use this syntax: • macrogroupname.macroname
Convert Macro to VB • Tools/Macro/Convert macros to VB
Other situations you must use macros • Make global key assignments. • AutoKeys macro • Carry out an action or a series of actions when a database first opens. • AutoExec macro
Assign an action or set of actions to a key AutoKeys Macro • You can assign an action or set of actions to a specific key or key combination by creating an AutoKeys macro group When you press the key or key combination, Microsoft Access carries out the action. If you assign an action to a key combination that is already being used by Access (for example, CTRL+C is the key combination for Copy), the action you assign this key combination replaces the Access key assignment.
Steps to Create AutoKeys Macro • In the Database window, click Macros under Objects. • Click New. • Click Macro Names on the toolbar. • In the Macro Name column, type the key or key combination to which you want to assign the action or set of actions • Add the action or set of actions you want the key or key combination to carry out. For example, you could add a RunMacro action that runs the Print Current Record macro when CTRL+P is pressed. • Repeat steps 4 and 5 for any other key assignments you want to make. • Save the macro group with the name AutoKeys.
Examples of Key Combinations These key combinations are a subset of the syntax used in the SendKeys statement in Microsoft Visual Basic.
Control how an Access file looks and behaves when it opens • 1. Set startup options • On the Tools menu, click Startup. • Select the options or enter the settings you want to use. • Or • 2. Create a macro that runs when an Access file first opens • Create a macro containing the actions you want to run when you open the database. • Save the macro with the name AutoExec.