N
Nando
Hi all! I have created two class modules: Book and Bookshelf. The last one
is implemented as a collection of items of the first one. I have included
the function NewEnum() in the Bookshelf class, so I can iterate through the
elements of the collections using a "For Each" loop. The problem is that
code below comes up with a runtime error '438': "Object doesn't support this
property or method." However this code does work under VB6. What's wrong?!
How can I make it to work under Access XP? The only way I can get it to work
is using the second code "FormV2_Load()"
'This version does not work
Private Sub Form_Load()
Dim MyBookshelf As Bookshelf
Dim Item As Book
Me.List1.RowSourceType = "Value List"
Set MyBookshelf = New Bookshelf
For Each Item In MyBookshelf
Me.List1.AddItem Item.Title & vbTab & Item.ISBN
Next Item
Set Item = Nothing
Set MyBookshelf = Nothing
End Sub
'This version does work
Private Sub FormV2_Load()
Dim MyBookshelf As Bookshelf
Dim Item As Book
Dim c As Long
Me.List1.RowSourceType = "Value List"
Set MyBookshelf = New Bookshelf
For c = 1 To MyBookshelf.Count
Set Item = MyBookshelf.Item(c)
Me.List1.AddItem Item.Title & vbTab & Item.Author & vbTab &
Item.ISBN
Next
Set Item = Nothing
Set MyBookshelf = Nothing
End Sub
Below is the code I included inside Bookshelf to make sure I can use the
"For Each .. Next". This is the collection object enumerator, so it can know
how to iterate through the items in the collection:
' NewEnum must return the IUnknown interface of a
' collection's enumerator.
Public Function NewEnum() As IUnknown
Set NewEnum = mcolEmployees.[_NewEnum]
End Function
I appreciate it your assistance. Thanks!
is implemented as a collection of items of the first one. I have included
the function NewEnum() in the Bookshelf class, so I can iterate through the
elements of the collections using a "For Each" loop. The problem is that
code below comes up with a runtime error '438': "Object doesn't support this
property or method." However this code does work under VB6. What's wrong?!
How can I make it to work under Access XP? The only way I can get it to work
is using the second code "FormV2_Load()"
'This version does not work
Private Sub Form_Load()
Dim MyBookshelf As Bookshelf
Dim Item As Book
Me.List1.RowSourceType = "Value List"
Set MyBookshelf = New Bookshelf
For Each Item In MyBookshelf
Me.List1.AddItem Item.Title & vbTab & Item.ISBN
Next Item
Set Item = Nothing
Set MyBookshelf = Nothing
End Sub
'This version does work
Private Sub FormV2_Load()
Dim MyBookshelf As Bookshelf
Dim Item As Book
Dim c As Long
Me.List1.RowSourceType = "Value List"
Set MyBookshelf = New Bookshelf
For c = 1 To MyBookshelf.Count
Set Item = MyBookshelf.Item(c)
Me.List1.AddItem Item.Title & vbTab & Item.Author & vbTab &
Item.ISBN
Next
Set Item = Nothing
Set MyBookshelf = Nothing
End Sub
Below is the code I included inside Bookshelf to make sure I can use the
"For Each .. Next". This is the collection object enumerator, so it can know
how to iterate through the items in the collection:
' NewEnum must return the IUnknown interface of a
' collection's enumerator.
Public Function NewEnum() As IUnknown
Set NewEnum = mcolEmployees.[_NewEnum]
End Function
I appreciate it your assistance. Thanks!