Enumerating VBA Collection Class that Implements a standard Collection Class Interface

I have standardised my custom collection classes, in a Microsoft Access 2003/VBA application, via a collection class interface named ICollectionClass. In addition to providing an interface, ICollectionClass includes standard code for each of the basic Collection Object properties and methods (i.e. Item, Count, etc.), and so those collection classes that implement ICollectionClass also instantiate an ICollectionClass object and call on its methods in the corresponding functions.

I know how I can enable enumeration for ICollectionClass, by adding the requisite NewEnum public function and setting the corresponding enumeration attributes. But how can I enable enumeration on the 'derived' collection classes that implement ICollectionClass?
ICollectionClass
-------------------
Private mcol As Collection
Private mParent As Object
 
Private Sub Class_Initialize()
    Set mcol = New Collection
End Sub
 
Public Function NewEnum() As IUnknown
    ' Enumeration function for the collection
    Set NewEnum = mcol.[_NewEnum]
End Function
 
Public Function Add(obj As Object, varID As Variant) As Boolean
    ' Add new member to collection
    mcol.Add Item:=obj, Key:=varID
End Function
 
etc.
 
Example Derived Class
----------------------------
Implements ICollectionClass
 
Private mcol As ICollectionClass
 
Private Sub Class_Initialize()
    Set mcol = New ICollectionClass
End Sub
 
Private Function ICollectionClass_Add(obj As Object, varID As Variant) As Boolean
    mcol.Add obj, varID
End Function
 
etc.

Open in new window

rohan_mooreAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rohan_mooreAuthor Commented:
I've managed to nail this, and thought it may be valuable to later users to reference the relatively straightforward solution.

In each 'derived' collection class, the NewEnum function implemented by the ICollectionClass interface needs to be coded per the code snippet attached, and the Attribute entries added to the NewEnum and Item methods in the derived class too.
Private Function ICollectionClass_NewEnum() As stdole.IUnknown
    Set ICollectionClass_NewEnum = mcol.NewEnum
End Function

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

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.