I have several buttons coded with VBA behind an Access form. I will have a number of forms which will have these buttons in their footer (new, next, prev, duplicate etc). These buttons are not standard macros, but are simple enough to have the same code work across all of my forms.
How might I go about coding these buttons (which have the same names across all forms.. kind of template-like) so I don’t have to copy-paste the code in all my forms? Is there a way to write these buttons in a Module and have the form import that module’s text (kind of like most other languages)?
Just curious. Makes the code a lot cleaner/easier, as the beef of the programming is my own but others will be making small edits to the form code.
The simplest thing to do would be to create a
Functionfor each button’s functionality in a standard code module. Then change the Click property of each button from[Event Procedure]to the name of the function that corresponds with that button (eg,=MyPrevFunction([Form])).Note that in order for this to work you must specifically use
Functionand notSub. There is no requirement in VBA for a function to return anything, so simply substituting the wordFunctionforSubis all that is required to make the change.A picture is worth a thousand words.