[AccessD] Collections.. and what the heck am I doing wrong?

Ryan W wrwehler at gmail.com
Thu Feb 22 13:52:34 CST 2018


Module Header:

Public MyCol as Collection


Form_Open:
Set MyCol = New Collection
End Sub

Form_Delete:

if MyCol is Nothing then
   Set MyCol = New Collection
end if

   MyCol.Add me.MyValueToTrack
End Sub

Form_BeforeDeleteConfirm:
dim i as integer
dim var as variant

'try to iterate this way
for i = 1 to MyCol.Count
   Debug.Print MyCol(i)
   Debug.Print MyCol.Item(i)
Next i


'or this way
for each var in MyCol
     Debug.Print var
next var

'unset the object so my collection doesn't continually grow between deletes
Set MyCol = Nothing

End Sub



I'm trying to track when users delete multiple items on a form by using a
unique (PK) and then use that collection to iterate through it and perform
another operation based on that PK elsewhere....

However, when it comes to iterating through the collection (either as an
integer or variant) the debug.print statements always print null?

I don't use collections, really EVER.  I usually write this stuff out to a
temp table then read it back where I need it to perform other operations in
scenarios just like this.  But I figured why not learn something new..
collections in theory should be faster since it's all stored in memory
rather than an actual table on disk.


So am I not using the collection right?


More information about the AccessD mailing list