Scope And Lifetime of Class Object

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.
 
D

Dirk Goldgar

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
 
S

Schlauberger

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top