[RESOLVED] Multiple ComboBoxes Change Event? And ComboBox(variable)
I am working with 27 ComboBoxes on a UserForm that all work to form a model code. I have two questions...
First Question:
How do I make a private sub that is a change event if ANY of the combo boxes change?
Instead of:
Private Sub ComboBox1_Change()
Private Sub ComboBox2_Change()
Private Sub ComboBox3_Change()
...
...
...
Private Sub ComboBox27_Change()
Use This:
Private Sub Any ComboBox_Change() - how do I do this?
Second question:
How do I refer to a variable combo box?
If n = 5, then refer to ComboBox5
Thanks for any help you can offer...
Rookie
Re: Multiple ComboBoxes Change Event? And ComboBox(variable)
You should create a control array. Then you can access your comboboxes like this :
VB Code:
Private Sub ComboBox_Change(Index As Integer)
ComboBox(2).ListIndex = 7 '<--- number in the parenthesis shows which combobox you are accessing
Re: Multiple ComboBoxes Change Event? And ComboBox(variable)
Manavo,
Thank you, but I'm still lost. If I'm a first grader trying to understand Calculus, just let me know and I'll drop it, but I don't know how to establish an array. Is that a simple declaration statement? I can't find anything in the archives or in VBA help.
Rookie
Re: Multiple ComboBoxes Change Event? And ComboBox(variable)
It seems that this can't be done in VBA, I was thinking that it could since it can be done in VB6 but it seems it can't :(
Re: Multiple ComboBoxes Change Event? And ComboBox(variable)
Try this....it will works in ACCESS... :)
VB Code:
Me("combo" & CStr(i)).value
All the best :thumb:
Anu..
Re: Multiple ComboBoxes Change Event? And ComboBox(variable)
Anu,
Yes, the below works. Thanks...
Rookie
i = 7
MsgBox Me("ComboBox" & CStr(i)).Value