multiple controls calling same procedure

hbeer444

Brian Rypstra
Local time
Yesterday, 17:03
Joined
Sep 3, 2009
Messages
15
Having never used class modules before, I am wondering if i am able to define my own custom object like a command button, that has common methods with each new instance of the same button.

In my current concept, I have a form with about 20 command buttons whose click, gotfocus & etc events are exactly the same except the procedure they call needs to know the name of the button that called it & make mods to that button. This would require the making of 20 buttons on this form, and 3 x 20 (at least) events, and at least 3 procedures.

Would it be easier to make a user defined object in a class module whose methods are those 3+ procedures, and on opening the form, populate the form with several instances of that button? Or could that be done in design view before hand? Or is this just as much work? Or - even not possible?

I hope I am clear, I will look more into the class modules after I get some responses if others think its the way to go.

thanks for your time!
 
Last edited:
I don't think VBA classes support this behavior. In .NET a class can inherit another class and you can overrirde methods with your own custom ones, I don't believe this is possible in Access VBA.

If you had a VB6 compiler you could make an activex control that could be added in and used on your form.
 
As you have to use the buttons, I think you are going to be stuck just copying and pasting the events and modifying them for whatever is unique. Or create a main function in a standard module and then for the click event of each button you put

Call MyFunctionName("MyControlName")

Which then would pass the name to the function and you can deal with it in that one function.
 

Users who are viewing this thread

Back
Top Bottom