I am trying to write code that will handle the "change" event of any ComboBox on my userform.
I went by this question's answer and created a separate class, etc.
However, it doesn't work. Using the same code on a new project works fine, this code on this project works sometimes when I use the "step by step" execution (F8), but when using normal running it doesn't.
Looking at other people's similar predicaments I added "DoEvents" but that didn't help.
This is my code in the UserForm
Private Sub UserForm_Initialize()
Dim ComboBox_Collection As Collection
Dim ctrl As Control
Dim cbc As ComboBox_Class
Set ComboBox_Collection = New Collection
For Each ctrl In UserForm1.MultiPage.Pages(2).Controls
DoEvents
If TypeName(ctrl) = "ComboBox" Then
DoEvents
Set cbc = New ComboBox_Class
Set cbc.Control = ctrl
ComboBox_Collection.Add cbc
DoEvents
End If
Next ctrl
Set cbc = Nothing
End Sub
And the class module, named "ComboBox_Class":
Private WithEvents TriggerComboBox As MSForms.ComboBox
Public Property Set Control(CB As MSForms.ComboBox)
Set TriggerComboBox = CB
End Property
Private Sub TriggerComboBox_Change()
MsgBox ("yay")
End Sub