Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Public Variables

Status
Not open for further replies.

inastrol

Programmer
Aug 8, 2002
5
US
Why can't my Access 2002 application recognize public variables?

I have a couple variables that I want made available to the entire application. I have declared them as Public in the General Declarations section of the startup form for the application. When I try to use a SET to initialize these variables in the Form_Open event for this form, I get a runtime error 2465 that says &quot;<Application name> can't find the field <field name> refered to in your expression&quot;.
 
Hiya,

Declare application global's (or public's) in a module instead.

A module's scope encompasses the application - the startup form is a form within the application. It's 'public' declarations are public to itself only (and sub-objects within it).


Regards,

Darrylle &quot;Never argue with an idiot, he'll bring you down to his level - then beat you with experience.&quot;
 
I put the declarations in a subroutine is standard module and then did a call to this subroutine from the forms open event to initialize the public variables.

When I tried to reference the public variables in other events connected to the form, I get a compile error stating &quot;Object Required&quot;. When the subroutine closed after it was called and set the values, did the public variables go away too?

I'm really frustrated with how to get Access do what I want.

Thanks is advance for any assistance provided.
 
Hiya,

A, the subroutine is defined in a module - yes?
B, are the variables defined in the module or the sub?

As an experiment, just define the vars in the module - NOT in a sub.

ok?

Regards,

Darrylle
&quot;Never argue with an idiot, he'll bring you down to his level - then beat you with experience.&quot;
 
I figured out the problem.

I was using the SET keyword to assign the value of the public variables. For some reason, Access 2002 doesn't like this. When I just said PublicVariable = FormVariable without the SET, it works ok.

Thanks for your advice, though. I didn't understand that public variables have to be established in a &quot;standard&quot; module, not a &quot;form&quot; module.

Terry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top