This is regarding the faq 707-4976,Understanding events (iv)A substitute for control arrays in VBA posted in this Forum.
The aim is to handle two command buttons named cmd1 and cmd2 in a user form named frmCol.
I put the following code in a class module named cCB and created a user form which has two command buttons cmd1 and cmd2(This code is from the faq 707-4976,I am not the original author)
could u please tell me what is the next step to handle two command buttons in the userform, using the created class module cCB.
-----------------------------------------------------------
Private WithEvents m_CB As MSForms.CommandButton
Private m_Form As frmCol
Public Sub Init(ctl As CommandButton, frm As frmCol)
Set m_CB = ctl
Set m_Form = frm
End Sub
Private Sub m_CB_Click()
m_Form.Info m_CB
End Sub
Private Sub Class_Terminate()
Set m_CB = Nothing
Set m_Form = Nothing
End Sub
An instance of this class should button click event (one instance– one button), and keep information on userform that instantiated it.
The frmCol module:
Private colCB As New Collection
Private ctlCB As cCB
Private Sub UserForm_Initialize()
Set ctlCB = New cCB
ctlCB.Init cmd1, Me
colCB.Add ctlCB
Set ctlCB = New cCB
ctlCB.Init cmd2, Me
colCB.Add ctlCB
End Sub
Public Sub Info(ctl As MSForms.CommandButton)
MsgBox "click by: " & ctl.Caption
End Sub
----------------------------------------------------------
Thankx
The aim is to handle two command buttons named cmd1 and cmd2 in a user form named frmCol.
I put the following code in a class module named cCB and created a user form which has two command buttons cmd1 and cmd2(This code is from the faq 707-4976,I am not the original author)
could u please tell me what is the next step to handle two command buttons in the userform, using the created class module cCB.
-----------------------------------------------------------
Private WithEvents m_CB As MSForms.CommandButton
Private m_Form As frmCol
Public Sub Init(ctl As CommandButton, frm As frmCol)
Set m_CB = ctl
Set m_Form = frm
End Sub
Private Sub m_CB_Click()
m_Form.Info m_CB
End Sub
Private Sub Class_Terminate()
Set m_CB = Nothing
Set m_Form = Nothing
End Sub
An instance of this class should button click event (one instance– one button), and keep information on userform that instantiated it.
The frmCol module:
Private colCB As New Collection
Private ctlCB As cCB
Private Sub UserForm_Initialize()
Set ctlCB = New cCB
ctlCB.Init cmd1, Me
colCB.Add ctlCB
Set ctlCB = New cCB
ctlCB.Init cmd2, Me
colCB.Add ctlCB
End Sub
Public Sub Info(ctl As MSForms.CommandButton)
MsgBox "click by: " & ctl.Caption
End Sub
----------------------------------------------------------
Thankx