3 4
If you need to run a macro action only if a condition is met-such as a specific form being open-you can create a condition expression in the macro's Condition column. A condition expression must evaluate to True or False; if it's True, the macro action runs; if it's False, the action is skipped. If you need to run one macro action if a condition is True and another if it's False, you need to write two macro rows with different conditions (one the negation of the other).
To write a macro with conditions that will open one form on a weekday and another form on a weekend day, follow these steps. (The two forms referenced in the macro are found in the sample database Test Access 2002.)
Weekday(Date())=0 Or Weekday(Date())=7
(This expression selects Saturday and Sunday only.)
Weekday(Date())<>0 And Weekday(Date())<>7
(This expression selects weekdays only.)
To test the macro, run it from the Macro Designer by clicking the Run button on the toolbar. If you run the macro on a weekday, frmOrdersWeekdays opens; if you run the macro on a weekend day, frmOrdersWeekends opens.
Troubleshooting - I imported a macro into a database, and when I run it, I get the message The expression you entered has a function name that databasename can't find
A great many macros use a function named IsLoaded to determine whether a form is loaded before running a database action. If you don't have this function in a module in your database, you'll get this error message when you run a macro that uses IsLoaded.
The IsLoaded function is located in the Utility Functions module in the sample Northwind database. To import it into your current database, follow these steps:
The Utility Functions module now contains the IsLoaded function, which will be available for use in VBA code and macros in your database.