?
Solved

Enumerating VBA Collection Class that Implements a standard Collection Class Interface

Posted on 2008-10-26
1
Medium Priority
?
3,195 Views
Last Modified: 2012-06-27
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

0
Comment
Question by:rohan_moore
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 

Accepted Solution

by:
rohan_moore earned 0 total points
ID: 22808828
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

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Suggested Courses

764 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