Title: What is a macro?
1A C C E S S
D A T A B A S E
T U T O R I A L
Menu
D E C E M BB EEY RN What is a macro?
A 1 D 7 T , 2
02 10 71 7
In this article, you will learn all about macros
what they are and how they automate tasks for
users to save time. It examines the essentials of
making and using macros. A macro is a tool that
lets you automate tasks and integrate
functionality into your forms, reports, and
controls. For instance, if you incorporate a
command button to a form, you link the buttons
OnClick event to a macro. The macro will have the
commands that you want the button to perform
every time it is ticked. In Access, it is useful
to consider macros as a simplified programming
language that you compose by building a list of
actions to perform. When you create a macro, you
choose every action from a drop-down list then
fill in the needed information for every action.
Macros allow you to add functionality to forms,
reports, and controls without writing code in a
Visual Basic for Applications (VBA) module.
Macros give a subset of the commands that are
accessible in VBA, and most people find it
simpler to construct a macro than to write VBA
code. For instance, assume that you need to
begin a report right from one of your data entry
forms. You can add a button to your form then
make a macro that starts the report. You can
either have a standalone macro, which is then
bound to the OnClick event of the button, or
embed the macro directly into the OnClick event
of the button itself. In any case, when you tap
the button, the macro runs and starts the
report. You create a macro by using the Macro
Builder as shown in the illustration below.
2On the Create tab, in the Macro Code group,
click Macro.
Understand Macros The term macro is frequently
used to denote independent macro objects. A macro
object can contain several macros referred to as
a macro group. A macro group is shown in the
Navigation Pane as a single macro object though
it contains multiple macros. Unquestionably, it
is possible to make each macro in a separate
macro object, but it bodes well to gather some
related macros into a single macro object. The
name in the Macro Name column distinguishes every
macro. A macro comprises individual macro
actions. Most actions involve one or more
arguments. Moreover, you can assign names to
every macro in a macro group. You can also add
conditions to control how each action is run. The
succeeding sections will explain every feature in
detail. Macro names If your macro object
contains just a single macro, macro names are
needless. You can simply refer to the macro by
the name of the macro object. But in the case of
a macro group, you need to give a unique name to
every macro. Arguments An argument is a value
that gives information to the action, for
example, what string to show in a message box,
which control to operate on, and so on. Some
arguments are compulsory while others are
discretionary. When you choose the data macro
that you wish to run in the macro
designer, Access database identifies if the data
requires parameters. If it does, it displays text
boxes where you can type in the arguments.
Conditions
3A condition determines specific criteria that
must be met before an action will be run. You can
use any expression that evaluates to True/False
or Yes/No. The action will not be performed if
the expression evaluates to False, No, or 0
(zero). If the expression evaluates to some other
value, the action will be executed. One
condition can control two or more actions. You
can achieve this by writing an ellipsis in the
Condition column for each succeeding action that
you need the condition to apply to. If the
expression evaluates to False, No, or 0 (zero),
none of the actions are executed. If the
condition evaluates to some other value, all
actions are run. In Access database 2010, the
Macro Designer layout looks a lot like a text
editor. The three columns are replaced with
actions and conditional statements presented in a
familiar top- down format that is used by
programmers.
Use this expression to carry out the action
If
Florida is the City value in the field on the
form from which the macro was run.
CityFlorida
There are more than 20 entries in the OrderID
field of the Orders table.
DCount(OrderID, Orders)gt20
There are more than 2 entries in the Order
Details table for which the OrderID field of the
table matches the OrderID field on the Orders
form.
DCount(, Order Details, OrderIDForms!Ord
ers!OrderID)gt2
The value of the ShippedDate field on the form
from which the macro is run is no earlier than
1-Oct-2017 and no later than 1- Nov-2017.
ShippedDate Between 1-Oct-2017 And
1-Nov-2017
The value of the UnitsInStock field on the
Products form is less than 4.
Forms!Products!UnitsInStocklt4
The FirstName value on the form from which the
macro is run is null (has no value). This
expression is equivalent to FirstName Is Null.
IsNull(FirstName)
The value in the Country/state field on the form
from which the macro is run is US, and the value
of the TotalOrds field on the
Country/stateUS And Forms!
SalesTotals!TotalOrdsgt50
4SalesTotals form is greater than 50.
The value in the Country/state field on the form
from which the macro is run is Florida,
California, or Texas, and the postal code is not
5 characters long.
Country/state In (Florida, California,
Texas) And Len(PostalCode)ltgt5
You click OK in a dialog box in which the MsgBox
function displays Confirm changes?. If you
click Cancel in the dialog box, Access database
ignores the action.
MsgBox(Confirm changes?,1)1
The temporary variable that is used to store the
result of a message box is compared to 2
(vbCancel2).
TempVars!MsgBoxResult2
To make Access database temporarily skip an
action, input False as a condition. Temporarily
skipping an action can be helpful when you are
troubleshooting a macro. Macro actions Actions
are the essential building blocks of macros.
Access database gives many actions from which to
pick, enabling a wide assortment of commands. For
instance, some of the more frequently used
actions can open a report, search a record, show
a message box, or apply a filter to a form or
report. To view Part-2 of this series, (by Ben
Beitler ), Click here gtgt
SIGN UP AND GET FREE EBOOK
Enter Your Name
SignUp Now and Get FREE EBOOK in your inboxand
Every Friday, we send out amazing Tips and Tricks
to help you master Microsoft Access.
Enter Your Email
Send Ebook Now!
If youlikethispostthenpleasesharewithotherpeople
? Email
Tweet
Share 5
Share
Save
Likethis Loading...
Related What's the new Macro Features from the
release of Access database 2010?
5Microsoft Access Databases Pros Cons of Access
Macros
Using the MS Access Macro to Automate Your
Database
M S
A C C E S S
Leave a Reply Your email address will not be
published. Required fields are marked Comment
Name
Email
Website
Post Comment Notify me of follow-up comments by
email. Notify me of new posts by email.
P R E V I O U S Create a Report in Microsoft
access database 2016 Part 2 N E X T Whats
the new Macro Features from the release of Access
database 2010?
6Search
A C C E S S
2 0 1 6
E B O O K
O F F E R
U N D E R S T A N D I N G
A C C E S S
M A C
R E C E N T P O S T S MS Access Database Images
How To Correctly Handle Them ? Access Queries
Date Criteria May Not Always Work with MS Access
Query How to create an embedded macro? Create a
standalone macro Part 2 Whats the new Macro
Features from the release of Access database 2010?
R E C E N T C O M M E N T S benadt2017 on Access
Tab Control How To Create Multi-Page Forms
Kolade. O on Access Tab Control How To Create
Multi-Page Forms ms access forms on How to Build
Access Database Forms Microsoft Access 2016
Database eBook on Microsoft Access 2016 eBook
Offer MS access query on How to Build Access
Database Queries
C O N N E C T
U P
O N
F A C E B O O K
7Microsoft Access Database 4,766 likes
Like Page
Contac
M O R E
S O C I A L
M E D I A
A R C H I V E S Select Month
C A T E Select Category
G O R I E S
M Y
E Z I N E
A R T I C L E S . .
2010-2017 Access Database Tutorial
Terms Of Use
Priv acy Policy
Contact Us
Proudly powered by WordPress