Scope And Lifetime of Class Object

  • Thread starter Thread starter Schlauberger
  • Start date Start date
S

Schlauberger

I have a main form in an Access 2000 application that acts
as a menu. I would like to declare a class object and a
collection as a global variable so that I can access the
collection from numerous Form class objects. I have tried
to declare the object as public on the main menu (Main
Form always open) and instantiate them on the Load event,
but I have not been able to access the object collection
from another form. Any assistance would be greatly
appreciated.
 
Schlauberger said:
I have a main form in an Access 2000 application that acts
as a menu. I would like to declare a class object and a
collection as a global variable so that I can access the
collection from numerous Form class objects. I have tried
to declare the object as public on the main menu (Main
Form always open) and instantiate them on the Load event,
but I have not been able to access the object collection
from another form. Any assistance would be greatly
appreciated.

How have you declared these objects? Probably, all you need to do is
preface your references with a reference (through the Forms collection)
to the Main Form. For example,

Debug.Print Forms!MainForm.colMyCollection.Count
 
Thanks,

I did not realize that the reference had to be
prefaced with the form name, unlike a public modules
procedure or function. By adding "Forms!MainForm" I was
able to reference to class object.
 
Back
Top