Using a class module for several userforms, identify which userform is active
Greetings gentlemen, I found this code, and the truth is that it works very well, it is a class module that creates a matrix for different controls (textboxes, combobox, listbox, etc.) it is really very versatile since you can assign different events For each control, I would like to use it with several userforms, for this I would need to verify which userform is loaded or active when the event is activated, I imagine it is with a function, but this must be at the class module level, thanks for any ideas you can contribute. ..
Code:
'Inside the class module
Private m_PassedControl As MSForms.Control
Private WithEvents chk As MSForms.CheckBox
Private WithEvents cbo As MSForms.ComboBox
Private WithEvents lst As MSForms.ListBox
Private WithEvents opt As MSForms.OptionButton
Private WithEvents spn As MSForms.SpinButton
Private WithEvents txt As MSForms.TextBox
Property Set ctl(PassedControl As MSForms.Control)
Set m_PassedControl = PassedControl
Select Case TypeName(PassedControl)
Case "CheckBox"
Set chk = PassedControl
Case "ComboBox"
Set cbo = PassedControl
Case "ListBox"
Set lst = PassedControl
Case "OptionButton"
Set opt = PassedControl
Case "SpinButton"
Set spn = PassedControl
Case "TextBox"
Set txt = PassedControl
End Select
End Property
Private Sub cbo_Change()
PrintControlName
End Sub
Private Sub chk_Click()
PrintControlName
End Sub
Private Sub lst_Change()
PrintControlName
End Sub
Private Sub opt_Click()
PrintControlName
End Sub
Private Sub spn_Change()
PrintControlName
End Sub
Private Sub txt_Change()
PrintControlName
End Sub
Sub PrintControlName()
Debug.Print m_PassedControl.Name
End Sub
'Inside the userform
Public collControls As Collection
Private cMultipleControls As clsMultipleControls
Private Sub UserForm_Activate()
Dim ctl As MSForms.Control
Set collControls = New Collection
For Each ctl In Me.Controls
Set cMultipleControls = New clsMultipleControls
Set cMultipleControls.ctl = ctl
collControls.Add cMultipleControls
Next ctl
End Sub