Syntax For Collection

  • Thread starter Thread starter Scott
  • Start date Start date
S

Scott

I have a custom collection named CourseDates. In a procedure after I Dim Col
As Collection, what is the syntax to set Col = to CourseDates?

Thanks!

Scott
 
Scott said:
I have a custom collection named CourseDates. In a procedure after I Dim Col
As Collection, what is the syntax to set Col = to CourseDates?

Usually goes something like this:

' declare the type and instantiate it at the same time
dim colCourseDates as new Collection

OR

' declare the type
dim colCourseDates as Collection

' instantiante the collection
set colCourseDates = new Collection

' Add an item to the collection
colCourseDates.Add <key>, <value>
 
Thank you for responding!

The collection CourseDates already exists; I don't want to create a new
collection. I want to set Col = to CourseDates. So I have:
Dim Col As Collection
<What goes here?>

It would be the same as setting Col to the Forms collection.

Thanks,

Scott
 
Scott said:
I have a custom collection named CourseDates. In a procedure after I Dim Col
As Collection, what is the syntax to set Col = to CourseDates?

Thanks!

Set Col = CourseDates

This doesn't create a new collection, it merely lets (the pointer) Col
point to (the same location as) CourseDates. Changes in the one are
changes in the other;

so why do you want this?
 
I'm just learning about collections and am not sure of their life. I create
the CourseDates collection in one form using the New method. I then need to
refer to the CourseDates collection in another form and I am thinking that I
have to Dim and Set a variable to be able to refer to the collection. I
don't know enough yet to know if CourseDates even exists any more after I
close the form that created it. Thanks for any enlightenment you can
provide.

Scott
 
Scott said:
I'm just learning about collections and am not sure of their life. I create
the CourseDates collection in one form using the New method. I then need to
refer to the CourseDates collection in another form and I am thinking that I
have to Dim and Set a variable to be able to refer to the collection. I
don't know enough yet to know if CourseDates even exists any more after I
close the form that created it. Thanks for any enlightenment you can
provide.


If the collection variable is dimmed and set in the first form it
will be destroyed when the form is closed. You can however dim a
public collection variable in the second form and set it equal to
the collection variable in the first form before the first form is
closed.

DoCmd.OpenForm "Form2"
Set Forms("Form2").colInFrm2 = colInFrm1
Docmd.Close acForm, Me.Name
 
Back
Top