Friday, 9 October 2015

When to use an AutoExec macro

An AutoExec macro is a smart way of running a series of actions every time your database is started. Unless you bypass the start-up (by holding down the shift key), this macro will always be run when the database loads. If you want to perform actions not supported in macros, simply write them as a function in a module and use RunCode from within the AutoExec macro to call them. Also if, for reasons best known to yourself, you don't want to call your start-up macro 'AutoExec', call it something else and then use the /x command line parameter to reference it.

There doesn't seem to be a great deal more to say about AutoExec macros, does there? Well, I will point out that there is a faster alternative if (and only if) you also load a start-up form. If it is suitable to do so, consider putting a VBA equivalent to the AutoExec macro in the OnLoad event of your start-up form. This will speed up your's database load time if the form already has a module (i.e. there is already some VBA on the form). This is because Access only has to load the form and its module into memory, rather than the AutoExec macro, the form and its macro. Okay, so it might only save half a second but, as I have mentioned elsewhere, performance is key to me; as Paul Daniels used to say, every second counts!

No comments:

Post a comment