Hi There,
I have created some dynamic command buttons that are created on the fly and have created a class module for them to execute their respective code.
I have got it working to execute code from these dynamic command buttons, but am having trouble passing variables from the userform into the class modules.
Any ideas/help would be appreciated
Thanks Kurt
Userform Code:
~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~
Class Module Code
I have created some dynamic command buttons that are created on the fly and have created a class module for them to execute their respective code.
I have got it working to execute code from these dynamic command buttons, but am having trouble passing variables from the userform into the class modules.
Any ideas/help would be appreciated
Thanks Kurt
Userform Code:
~~~~~~~~~~~~~~~~~~~~~~~~~~~
VBA Code:
Option Explicit
Public MyEvents As New Collection
Private Sub UserForm_Initialize()
Dim tmpCtrl As Control
Dim CmbEvent As clsMyEvents
Dim x As Long
'Add some dummy data for the combo-boxes.
Sheet1.Range("A1:A5") = Application.Transpose(Array("Red", "Yellow", "Green", "Blue", "Pink"))
Sheet1.Range("B1:B5") = Application.Transpose(Array(1, 2, 3, 4, 5))
Sheet1.Range("C1:C5") = Application.Transpose(Array(5, 4, 3, 2, 1))
Next x
For x = 1 To 5
Set tmpCtrl = Me.Controls.Add("Forms.CommandButton.1", "MyButton" & x)
With tmpCtrl
.Left = 100
.Width = 50
.Height = 20
.Top = (x * 20) - 18
.Caption = "Num " & x
End With
kk = "test"
Set CmbEvent = New clsMyEvents
Set CmbEvent.MyButton = tmpCtrl
MyEvents.Add CmbEvent(kk)
Next x
End Sub
~~~~~~~~~~~~~~~~~~
Class Module Code
VBA Code:
Option Explicit
Public WithEvents MyCombo As MSForms.ComboBox
Public WithEvents MyButton As MSForms.CommandButton
Private Sub MyButton_Click(kk)
' Dim BtnNum As Long
'
' BtnNum = Replace(MyButton.Name, "MyButton", "")
' MsgBox MyButton.Name & " is " & IIf(BtnNum Mod 2 = 0, "even", "odd")
'MsgBox ("test" & CStr(i))
MsgBox (kk)
End Sub