How do I avoid copying functions into different objects
Posted on 2014-12-25
I am developing a system that displays data in several different ways for different groups of users. However many of the fields and associated functions are the same. E.g. when a CompletedDate is updated for a field I need to do several other functions depending on the value of data in related fields. To accomplish this I have created an AfterUpdate event and associated function in the form's VBA library. Both the AfterUpdate event and Function refer to other fields on the form (e.g. me.AssignedTo).
When I implement the same functionality on another form I can copy the AfterUpdate event and function into the new form's VBA but every time I change the code I have to remember to change it in multiple places.
I know I could put the Function in a standard module but then I would need to feed to the function multiple field values; I can't just reference them by me.AssignedTo nor can I specifically reference them by using the form name because the same function could be called by multiple forms.
Is there any way to easily feed, or reference, all the fields to a function or what is the generally accepted approach to use in this case to keep the code as tidy as possible?