Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VBA Adding a class to a collection [duplicate]

I have a class module called Holding. In it are several public variables. My code is this:

Dim holdings as Collection
Dim h as Holding

Set holdings = new Collection

For i = 1 to last
    Set h = new Holding

    h.x = y
    '... etc

    holdings.Add(h)
Next i

This gives me error "object doesnt support this property or method" on the holdings.Add(h) line, but everywhere I look, it gives this exact example of how to achieve this. What am I missing?

like image 370
Logan Avatar asked Jun 13 '11 13:06

Logan


1 Answers

Remove the parentheses.

holdings.Add h

Otherwise you are trying to add to the collection the value of the default property of your Holding instance, and it doesn't have a default property.

like image 182
GSerg Avatar answered Oct 28 '22 17:10

GSerg