Ok, found my code, there are a couple steps involved. I will post my code, which again is used for a calendar control, with 40 labels representing the days of this month +/- a week or so. The idea is that the user clicking any of the labels will fire off just one procedure.
1) First, create a class module from the insert menu. Give the module a relevant name, it will be used in your code. Mine is called clsControlEvents
2) Add this code to the class module:
Code:
Public WithEvents Lbl As MSForms.Label
Public Frm As UserForm
Private Sub Lbl_Click()
Lbl.BorderColor = &HFF& 'this is where you set the main action you want to occur
End Sub
3) Now let's move chronologically, starting with when the user clicks one of my date textboxes.
Code:
Private Sub txtExpCloseDate_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
'i've stripped out some other stuff, here's the only relevant bits. Clicking the textbox
'launches my calendar form
frmCal.Calendar_Change
frmCal.Show
'now my calendar form is showing, and the user is about to click on one of the labels representing a day of the month.
End Sub
4) Here's where the magic happens. You have to modify this. Since I'm loading a calendar form, all my code is tied to the form initialize event. You will want to change this to something else, probably the initialize event of your main form. Here we loop through all the controls on the form. I set the tag property of the labels I wanted to use with numbers 1 thru 42. Those labels that are tagged get the special Class treatment. Labels that are just plain old labels get skipped this way.
Code:
Dim colLabels As New Collection 'this is a form level variable
Private Sub UserForm_Initialize()
'initialize class variables
Dim Ctl As MSForms.Control
Dim obEvents As clsControlEvents
For Each Ctl In Me.Controls
If TypeOf Ctl Is MSForms.Label And Ctl.Tag <> "" Then
Set obEvents = New clsControlEvents
Set obEvents.Lbl = Ctl 'Lbl and Frm were the two variables dimmed in the class module remember?
Set obEvents.Frm = Me
colLabels.Add obEvents
End If
Next Ctl
End Sub
5) That should do it. At this point, if any of the labels get clicked, the first procedure back in the class module will get kicked off.
Hopefully you followed all that, and you can modify this to suit your own needs.