Office 2007 - Access

Lesson 64: Macros

64/72 Lessons 

Independent “Macro

A “Macro” in “Access” is different  a “Macro” in other “Microsoft Office” applications.

A “Macro” in “Access” is comprised of various actions, while a “Macro” in “Excel” for example, consists of the inclusion of a number of mouse clicks, or certain buttons.

We have two different macros, you have the independent “Macro” and you have an embedded “Macro”.
An independent “Macro” appears as a separate object in the database and afterwards we can connect to some event, eg clicking a button.
An embedded “Macro” is directly assigned to the event.

This is evident in the following example.

In this example I make an independent “Macro” that opens the “CustomersPhone” report.

Click the “Macro” button under the “Create” tab in the “Ribbon”.
This opens the “Macro” window:

In the upper part of the window, we define the new “Macro”.

A “Macro” can, as mentioned earlier, include several “Macro” actions .
We enter the ‘Macro” action in the first column, the  “Action” column.
Each row in this column may contain a “Macro” action.

In the second column, we give the argument for the “Macro” action selected in the first column.
So what I wanted to do was, open the “Customers Phone” report through this “Macro”.
I click the downward pointing arrow next to the first field of the “Action” column.
From the drop-down menu that appears, choose the “Open Report” action.

In the lower part of the window, I find the “Action Arguments” section, for this action.
I select the “Report Name”. Click the downward-pointing arrow that appears, and choose the report that I wish to open from the list, in this case ” Customers Telephone.”
I want to open this report in “Print Preview” so I click the “View” box in the lower part of the window, and select “Print Preview” as the second argument.


I click the “Save” button in the “Quick Access” toolbar and enter the appropriate “Macro” name, eg “Macro open phone report”.

The “Macro” group will appear under the “Macros” in the “Navigation pane” of “Access”.
When you double-click this, the “Macro” is executed and this opens the report in view “Print Preview”.

Now this is not much, we might as well double-click the report in the “Navigation Pane” and it will just do the same.

Right.

The only difference is that this “Macro” can now be performed by any button that you add to any form.

To do this, open the form in which you want to add the button to, in “Design View”.

Choose the “Button (Form Control)” in the “Ribbon”.

Click and drag in the form where you want to add the button.

In the first window of the “Command Button Wizard” choose “Miscellaneous” as a category and “Run Macro” action.

Click “Next”.

In the next window, select the “Macro” you just created.

Click “Next”.

In the next window, you determine whether you want the button with text or an image.

I choose “text”, type some appropriate text and click “Next”.

In the next window, I give the button a meaningful name, you never know when we want to refer this and click the “Finish” button.

I save the form and see the result in “Form View”.

In the next lesson we will look at how we add a “Macro” to a button.

Awesome!
You've completed Lesson 64
START NEXT LESSON