How to add a type to a collection ??

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm trying to add a type to a collection and am getting an error message I do
not understand.

I defined the type in a public module, defined a variable based on this type
and assigned valued to the elements. When I do a .Add to the collection, I
get the error message. I'm using "colCollection.Add myType". This is the
first time I have ever attempted to add a type to a collection and it is
critical to my design that this can be done somehow. I hate to have to go
back to using separate arrays for each element in my type.

Soirry, I know of no way to cut and paste a MS Access error message. I'm
using Access 2000.
 
I have never used classes and don't know how and have no time to learn for
this project I'm working on.
I just don't understand why I can't add a user-defined type to a collection.
I can do it with strings and integers so why not with a user-defined type. it
makes no sense to me. My Access book is 1600 pages and make no mention of
this topic.
 
There's really very little to it, and it has the not insignificant advantage
of actually working. Here's an example from one of my own projects ...

The class module (clsVisibleObject) ...

Option Compare Database
Option Explicit

Private mstrObjectName As String

Public Property Let ObjectName(ByVal strObjectName As String)

mstrObjectName = strObjectName

End Property

Public Property Get ObjectName() As String

ObjectName = mstrObjectName

End Property

Some code that adds instances of this class to a collection ...

Public Sub HideForms(ByRef colForms As Collection, Optional ByVal
strCallerName As String)

Dim obj As Object
Dim vo As clsVisibleObject

If colForms Is Nothing Then
Set colForms = New Collection
End If
For Each obj In Forms
If obj.name <> strCallerName Then
If obj.Visible = True Then
obj.Visible = False
Set vo = New clsVisibleObject '<-- instantiate the class
vo.ObjectName = obj.name '<-- assign value to property
colForms.Add vo, vo.ObjectName '<-- add to collection, use
property value as key
Set vo = Nothing
End If
End If
Next obj
Set obj = Nothing

End Sub
 
Back
Top