Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run a subprocedure from a macro 3

Status
Not open for further replies.

SlakeB

MIS
Jun 15, 2005
40
US
Does anyone know how to run a subprocedure from a macro? The sub I want to use is currently associated with a button (Sub Command0_Click()). This sub does a number of things like running a few macros and opening a few queries.

I'm hoping to replace the button with a macro that has all of the same functionality.
 
The RunCode action may launch a VBA Function, not Sub.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
is there a way to call a function which calls the sub?
And where should I put a function in order for it to be accessable by the RunCode action?
 
We usually don't encourage macros, for several reasons...

A macro can't call a sub, only a function, which can be done through the RunCode action of a macro, as stated by PHV. I'm not sure, but I don't think a function called from a macro may have any parameters either...

Rather build subs or functions with VBA to do so.

Then you can call subs or functions as much as you like, for instance calling the click event procedure you mention above, can be done using for instance:

[tt]call Command0_Click[/tt]

from within the form module.

For a function to be available for the RunCode action, I think it will need to be created within a standard module, not a forms/reports module (in VBE - Insert | Module).

Roy-Vidar
 
How are ya SlakeB . . . . .
SlakeB said:
[blue]is there a way to call a function which calls the sub?[/blue]
Sure!

[ol][li]Copy the body of the code in your button event ([blue]not the Private & End Sub lines[/blue]).[/li]
[li]In a module in the modules window, [purple]insert a new function.[/purple] ([blue]Remember the name you assign[/blue]).[/li]
[li]Paste the copied code, then save/close the module.[/li]
[li]Go back to the event for your button and replace the code with:
Code:
[blue]   Call [purple][b]YourFunctionName[/b][/purple][/blue]
.[/li]
[li]Then use [blue]PHV's[/blue] suggestion to call the function from your macro . . . .[/li][/ol]

Calvin.gif
See Ya! . . . . . .
 
SlakeB . . . . .

[blue]Roy Vidar[/blue] and I were posting at the same time, so I didn't get to see his post until I finished.

Take heed to his post. [blue]Its a much better road to travel![/blue] Other than things to do during [blue]startup[/blue] of the DB, [purple]Macro's are all but gone . . . . .[/purple]

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top