No UDT's allowed in Collections?

J

Jon Furman

I just ran into a strange annoyance, I wanted to add a variable that was
declared as a UDT to a collection and received the following compilation
error:

"Only user-defined types defined in public object modules can be coerced to
or from a variant or passed to late-bound functions"

Now my type definition is declared public in a separate module and the
variable I'm using to add to the collection is Dim'd as the UDT type.
Everything works fine all up to the statement where I add the UDT variable
to the collection. I checked the documentation on collections and it states
that they can contain variables of ANY data type. So I'm not sure what's
going on here. I guess I could wrap the UDT in a class module but that's a
big pain for something so simple. Any one else seen this? Am I missing
something or is this a known VBA deficiency?

Thanks All!

Jon
 
M

Michel Walsh

Hi,


Make it a class, indeed, with public members. A public member is like a
private one, supplied with Let and Get properties making no validation. It
is not much more work that using a Type doing that.



Hoping it may help,
Vanderghast, Access MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top