Quick Trick: Copying Embedded Macros from one Property to another

Now that we spent all this time talking about templates, how about we put to use something we learned about it in a totally unexpected way? Remember that we talked about how embedded macros are really represented as SaveAsText/LoadFromText alongside objects?

Unlike VBA code associated with event properties (e.g. OnLoad, etc) and like other 'simple' properties (such as the Default view Property), you can copy an embedded macro from a control/form/report's property to another (or the same) control/form/report property.

The trick is that for each event property off of form/report/controls, there is a "shadow" property that contains the embedded macro for that event property. For example, the OnLoad property has a dual OnLoadMacro property that contains its embedded macro (if there is one, otherwise it's empty).

So, it's very easy to copy embedded macros around by simply writing code that looks like this:

Forms(0).Controls("foo").OnLoadMacro = Forms(1).Controls("bar").OnOpenMacro

Of course, if you look at what actually is in the .*Macro "shadow properties", you will find out that it is the same output that a DoCmd.SaveText acMacro, "foo", "Macro1" has. This means that you can easily load/save/copy standalone macros to/from embedded macros.