Using Macro Conditions in Access 2010

by rhyttinen on December 20, 2010

If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!

Today, we continue our discussion of macros and look at how to set macro conditions in the new Access 2010 macro designer.

In some cases, you might want to execute an action or a series of actions in a macro only if a particular condition is true. For example, you can use a macro to validate data in a form. Using conditions, you might want to display one message in response to one set of values and another message in response to a different set of values.

To execute macro actions only when certain conditions are true, you use an If block (this replaces the Condition column in previous versions of Access). When an If block is executed, Access evaluates the condition ñ if it is true, then Access carries out the action associated with the condition. If the condition is false, Access ignores the action and any immediately following actions for that condition.

You can evaluate more than one condition by using the Else if and Else blocks. For instance, if the first condition is false, Access moves to the Else if block and evaluates the condition there. If that condition is false, it then moves to the next Else if block (if any). If all conditions are false, then Access performs the action under the Else block.

Creating a conditional expression using the Macro Designer

In the condition example above, the condition references a control on a form. The syntax might at first appear strange to you although it is quite logical. This construction can also be used to reference controls on a form or on a report from queries, which can be quite useful. The syntax is broken down as follows:

Syntax to refer to an object on a form

To Use Macro Conditions

  1. Create a blank new Macro.
  2. Click the Add New Action drop-down arrow and choose If from the list.
    Or
    Expand the Program Flow category in the Action Catalog window and double-click If.
  3. In the Conditional Expression box, type the conditional expression
    Or
    Use the Expression Builder to create a conditional expression.
  4. Add the actions you want the macro to carry out if the condition is true.
  5. To test for more than one condition, click the Add Else If link.
  6. In the Conditional Expression box in the Else If box, type the conditional expression (or use the Expression builder to create the expression).
  7. Repeat steps 5 & 6 for any additional conditions you wish to test for.
  8. Repeat Steps 3 and 4 for any other conditions you want to include in the macro.
  9. To add an action that is to be executed if all conditions evaluate to false, click the Add Else link and then choose the action to be executed.

Similar Posts:

Share and Enjoy:
  • del.icio.us
  • Digg
  • TwitThis
  • Reddit
  • Technorati
  • Facebook
  • StumbleUpon
  • Google Bookmarks
  • Propeller
  • email

Comments on this entry are closed.

Previous post:

Next post: