By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,455 Members | 2,161 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,455 IT Pros & Developers. It's quick & easy.

running a macro

P: 3
I created a macro (OpenAllrpts) that opens 7 reports. In the argument section I have listed the name of the report and Print preview.
In the code behind the form the user will use I have docmd.runmacro OpenAllrpts. I'm getting an error that an argument is needed. What do I do?
Nov 16 '06 #1
Share this Question
Share on Google+
3 Replies


100+
P: 143
Can you post the maco. Incidentally, I would try to steer clear of macros. Use VBA instead, much more flexible. For instance, would you always want to run the seven reports together, or anyone of the on their own?
Nov 16 '06 #2

alexherrero
P: 10
I created a macro (OpenAllrpts) that opens 7 reports. In the argument section I have listed the name of the report and Print preview.
In the code behind the form the user will use I have docmd.runmacro OpenAllrpts. I'm getting an error that an argument is needed. What do I do?
I think you need to quote the name of the macro, so you would have

Expand|Select|Wrap|Line Numbers
  1. DoCmd.RunMacro "OpenAllrpts"
If you don't do that, the "MacroName" argument (not optional) will not be present, thus returning the error you see.

By the way, are you using the "Option.Explicit" statement at the beginning of the VBA module behind your form? It's always a good idea to have that one, and do a Compilation (Menu "Debug", item "Compile") before trying to run your code.

Just my 2 cents.
Nov 16 '06 #3

PEB
Expert 100+
P: 1,418
PEB
Maybe the VB help will be usefull:

VBA Help
RunMacro Method
RunMacro Method
See Also Applies To Example Specifics
The RunMacro method carries out the RunMacro action in Visual Basic.

expression.RunMacro(MacroName, RepeatCount, RepeatExpression)

expression Required. An expression that returns one of the objects in the Applies To list.

MacroName Required Variant. A string expression that's the valid name of a macro in the current database. If you run Visual Basic code containing the RunMacro method in a library database, Microsoft Access looks for the macro with this name in the library database and doesn't look for it in the current database.

RepeatCount Optional Variant. A numeric expression that evaluates to an integer, which is the number of times the macro will run.

RepeatExpression Optional Variant. A numeric expression that's evaluated each time the macro runs. When it evaluates to False (0), the macro stops running.


Remarks
For more information on how the action and its arguments work, see the action topic.

You can use macrogroupname.macroname syntax for the macroname argument to run a particular macro in a macro group.

If you specify the repeatexpression argument and leave the repeatcount argument blank, you must include the repeatcount argument's comma. If you leave a trailing argument blank, don't use a comma following the last argument you specify.


Example
The following example runs the macro Print Sales that will print the sales report twice:

DoCmd.RunMacro "Print Sales", 2
Nov 18 '06 #4

Post your reply

Sign in to post your reply or Sign up for a free account.