Using Collections

gblack

Registered User.
Local time
Today, 20:11
Joined
Sep 18, 2002
Messages
632
Hi,

I just read some about adding objects to a custom collection (Alison Balter's "Mastering Microsoft Access 2000 Delopment"), where you can go through and name everything in your collection.

I was wondering… If I had a collection of objects that were all named the same but had a sequential number distinguishing them, is there anyway to programmatically add them to a collection? As opposed to hard coding each name into a custom collection?

For example: I have textboxes in a form which are all named MM1YY, MM2YY, MM3YY… MM20YY…

Is there any way to add all of these to a collection using a loop? Or do I actually have to go one by one and write the code for each?

Example:
Dim colNames as Collection
Set colNames = New Collection
colNames.add “MM1YY”, “01”
colNames.add “MM2YY”, “02”
colNames.add “MM3YY”, “03”

colName.add “MM20YY”, “20”
etc…

Or is there some way I can loop through this? Sorry, I am not use to working with this kind of thing, but I’d like to understand it better… I am also not sure about the unique Key part of the add command. I the book I am using they both of the parameters are the same (e.g. colNames.add “Gary”, “Gary”). I wasn’t sure if I could change this…

Can anyone help here?

Thanks,
Gary B.
 
Try something like this:-

for iloop = 1 to 20
if me("MM" & iloop & "YY") = xx then 'whatever
next iloop

Regards .. Peter
 

Users who are viewing this thread

Back
Top Bottom