MacDaddyNickP
Programmer
I have a Collection Object called SvcTags to which I add a number of class objects called oSvcTag. The code executes fine in adding items to the collection, however, When I try to iterate through the collection of objects in a later step of the Procedure to view properties of the instantiated members of the collection, I only get data from the last added item. The code is below. How do I view data about the 'Jth element' of a collection. My experience with Collections is new.
Option Compare Database
Option Explicit
Public Sub TestClassSvcTag()
Dim SvcTags As New Collection
Dim oSvcTag As New clsSvcTag
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim i, j As Long
Dim Item As Object
'Set SvcTags = New Collection
Set db = CurrentDb
Set rs = db.OpenRecordset("SELECT DISTINCT [Service Tag Number] FROM D3_Tag_Data;")
j = 0
With rs
.MoveLast
.MoveFirst
For i = 0 To .RecordCount - 1
With SvcTags
'Dim oSvcTag As New clsSvcTag
j = j + 1
.Add Item:=oSvcTag, Key:=CStr(j)
oSvcTag.SvcTagID = rs![Service Tag Number]
oSvcTag.LoadComponents
oSvcTag.LoadSvcTagInfo
Debug.Print oSvcTag.SvcTagID
Debug.Print oSvcTag.Chassis
End With
.MoveNext
Next i
End With
j = 1
For Each Item In SvcTags
Debug.Print SvcTags.Item(j).SvcTagID
j = j + 1
Next Item
Stop
Set oSvcTag = Nothing
End Sub
The Class I am building works fine, It is getting to view/manipulate the various instantiations in the collection I'm unclear about.
Option Compare Database
Option Explicit
Public Sub TestClassSvcTag()
Dim SvcTags As New Collection
Dim oSvcTag As New clsSvcTag
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim i, j As Long
Dim Item As Object
'Set SvcTags = New Collection
Set db = CurrentDb
Set rs = db.OpenRecordset("SELECT DISTINCT [Service Tag Number] FROM D3_Tag_Data;")
j = 0
With rs
.MoveLast
.MoveFirst
For i = 0 To .RecordCount - 1
With SvcTags
'Dim oSvcTag As New clsSvcTag
j = j + 1
.Add Item:=oSvcTag, Key:=CStr(j)
oSvcTag.SvcTagID = rs![Service Tag Number]
oSvcTag.LoadComponents
oSvcTag.LoadSvcTagInfo
Debug.Print oSvcTag.SvcTagID
Debug.Print oSvcTag.Chassis
End With
.MoveNext
Next i
End With
j = 1
For Each Item In SvcTags
Debug.Print SvcTags.Item(j).SvcTagID
j = j + 1
Next Item
Stop
Set oSvcTag = Nothing
End Sub
The Class I am building works fine, It is getting to view/manipulate the various instantiations in the collection I'm unclear about.