Reputation: 3012
I have a macro assigned to the onClick event of a button in a form. How can I call this macro programmatically?
I tried
btnName_Click
But this does not work since there is no function called btnName_Click()
... obviously :)
I can access the onClick Member via Me.btnNewRecord.OnClick
but don't see a way to run the macro.
Upvotes: 4
Views: 16790
Reputation: 13112
After extensive searching, I do not believe it is possible to reference the embedded macro, and run it. You can view the XML of the macro, but I know of no way of running it or even accessing it beyond it's XML stored as a string. A possible work around would be to convert all macros to VBA. To do this:
now you should be able to call the button's code with btnName_Click
as you showed in your question. Obviously if you did this, you would sacrifice the advantage of using macros (i.e. limited functionality without the user needing to trust your database).
Original Answer, which doesn't apply to Embedded Macros:
Use DoCmd.RunMacro
Example:
Docmd.RunMacro(macroname)
where macroname
is a string representing the name of the macro.
Upvotes: 3