I have a form with approx 40+ command buttons on it. I need to add them to a collection so that I can click on one and have the click method picked up and executed depending which button was clicked. I have been fighting this for several weeks and looking at the boards....Can't seem to find exactly what I need.
[VBA]
Option Compare Database
Option Explicit
Public rptDate As Date
Public colDate As Collection
Private Sub form_load()
Dim n As Long
Dim m As Long
Dim i As Long
Dim strDte As String
Dim strCal As String
Dim ctl As Control
Dim cLEvents As clsCommandButton
Set colDate = New Collection
For Each ctl In Controls
If TypeName(ctl) = "CommandButton" Then
Set cLEvents = New clsCommandButton
Set cLEvents.mLGroup = ctl
colDate.Add cLEvents
Debug.Print TypeName(ctl)
End If
Next
End Sub
'The following is the Class clsCommandButton
Option Compare Database
Public WithEvents mLGroup As CommandButton
Private Sub mLGroup_Click()
Debug.Print "this is a test"
end sub
[/VBA]