?
Solved

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

Posted on 2004-10-08
1
Medium Priority
?
196 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 86

Accepted Solution

by:
Mike Tomlinson earned 1000 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…
Suggested Courses

831 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