Call an embedded macro from VBA in access
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:
- Open the form in design view.
- Click Convert Form's Macros to Visual Basic
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.
rob
Updated on June 24, 2022Comments
-
rob almost 2 years
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. -
rob over 11 yearshow can I figure out the name of the macro? The macro was auto-generated when I created the button. edit: didn't see your edit... yes it's an Embedded Macro :-/
-
rob over 11 yearsThx for your effort! Now that I know the available options I can figure out another solution:)