How to pass a reference of a member of a control array?

Hi Experts:

I need to modify the behavior of a combobox and am using a class module as the helper class.  It works fine passing in a single control, but I need to modify it to accept mambers of a control array.

In my form code I have this:

Private oCombo As cComboHelperArray

Private Sub cbArray_GotFocus(Index As Integer)
    'Attach the helper class to ComboBox array cbArray in the GotFocus event
    oCombo.AttachTo cbArray, Index
End Sub

And in the Class Module:

Private WithEvents moCombo As ComboBox

Public Sub AttachTo(oCombo As Variant, ByVal Index As Long)
    Dim c As Control
    'On Error Resume Next
    For Each c In oCombo
        If (c.Index = Index) And (TypeOf c Is ComboBox) Then
            Set moCombo = c '<< Error here 459: Object or Class does not Support the set of events
            Exit For
        End If
    m_Index = c.Index 'Save the index of the currently attached control
    Debug.Print "Attached " & oCombo.Name
End Sub

See the error 459 noted above.  Any ideas how I can set the helper combobox to get the events of the attached combobox array?

Thanks in advance...
Who is Participating?
Mike TomlinsonConnect With a Mentor Middle School Assistant TeacherCommented:
You can't use the WithEvents keyword to reference a control array in any way.

To trap events from inside your class module you will have to break out your control into individual controls.


Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.