VBA click event on array of combo boxes

Viewed 215

Hey all I have the following VBA code that allows me to have a click event on a dynamically created comboboxes and textboxes onto the userform.

userform:

Option Explicit

Dim comboboxBoxColct  As New Collection

Private Sub UserForm_Activate()
Dim comboboxEvent           As Class1
Dim controller(100)         As Object

   '..lots more code within here
   With controller(i)
      .Name = "cmdBOM" & i
      .Top = 10
      .ForeColor = vbBlack
      .Height = 15
      .FontName = "Times New Roman"
      .FontSize = 6
      .AutoSize = False
      .Caption = "Add New Row"
      .BackColor = RGB(204, 255, 201)
      .TabStop = True
      .TabIndex = i
   End With

   Set comboboxEvent = New Class1
   Set comboboxEvent.comboboxBox = controller(i)
   comboboxBoxColct.Add comboboxEvent
End Sub

Class1:

Option Explicit

Public WithEvents comboboxBox As MSForms.ComboBox

Sub SetCombobox(ctl As MSForms.ComboBox)
    Set comboboxBox = ctl
End Sub

Private Sub comboboxBox_Click()
    If comboboxBox.ListIndex > -1 Then
        MsgBox "You clicked on " & comboboxBox.Name & vbLf & _
               "The value is " & comboboxBox.Value
    End If
End Sub

The above code works just fine. However, once I click on the combo box and select something, the msgbox comes up saying:

You clicked on

The value is

There are no values for .Name or .Value when looking at the _Click() event and I'm not sure why that is? I place a break point on Set comboboxBox = ctl and it just seems to come up all the time with "".

enter image description here

What can I do in order to get this to work?

0 Answers
Related