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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use of global variables

Status
Not open for further replies.

astraltango

Programmer
Joined
Nov 19, 2003
Messages
18
Location
AU
I'm simply trying to set a global variable which is set by one form and accessed by another, but it is not working.

I have declared it as public in the first module, but don't seem to be able to access it in another module.

Any idea what I may be doing wrong?

I have tried declaring it as public in both modules to no avail.

Cheers
 
Try calling it as Form1.YourVariableName. When you say module, are you refering to the code for each form? If so, goto project.. Add Module, and add a new module. Now declare your variable as public in the new module and you should be able to access it by its name in the form's code
 
perhaps a little code example would be helpful

If I had to guess I would suspect you are not not giving the object name as well as the variable name when trying to set it

for example var1 declared public in form1 would be accessed in form2 as form1.var1


 
ah yes, I wasn't including the form name when referencing the variable

is there any other way to reference a global variable without specifying a specific form? (since that is defeating the purpose of using the public variable in the first place)

thanks again
 
Where are you declaring the variable?
For it to be a true global variable, it needs to be declared in a .bas module as global. If you declare it in a .frm or .cls, it is a module-level variable.

Note that I don't advocate their use, but sometimes there's no other way.

Chip H.


If you want to get the best response to a question, please check out FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top