Solved

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

Posted on 2004-10-08
1
171 Views
Last Modified: 2010-05-02
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
    Next
    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...
0
Comment
Question by:nichia
1 Comment
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 250 total points
ID: 12262665
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.

Sorry,

~IM
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now