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

Global variables being reset somehow !?!

Status
Not open for further replies.

gazolba

Programmer
Dec 4, 2001
167
US
Im declaring some global variables in a module that is executed at initialization.
These variables are not always present and I have no idea why.
For instance I set one of them in a form and then when I return to the previous form, the contents have gone.
Any ideas? I'm using Access 2000 with all the latest fixes.
 
Most likely you are missing something... Try adding a watch to the global variable and running your database and see where it is being cleared.

Also double check that you used the global key word in the public area of a module (just double checking).

Thirdly, try opening the database via the command line with the decompile switch to remove all compiled (and possibly corrupt) code. This is also a great time to also compact and then open a module and "Compile and Save All Modules".
 
And fourth ...

Make sure that you haven't declared a local variable with the same name where you are trying to reference the global. If you have then the local version of the variable will hide the global one. In design view, right click on the variable and select "Definition". That will show you where the version of the variable that you are referencing has been defined.
 
I read a discussion on comp.databases.ms-access where they mentioned that if you resume after an unhandled error, it resets all variable values, everywhere. So they recommend storing your globals in textboxes on a hidden form. That guarantees your global information won't be lost.

Being the structured/procedural programmer that I am, I religiously avoid globals and instead set up large OpenArgs parsing heirarchies that moves me between forms and reports.
 
Many thanks for all the tips.

The globals were disappearing after unhandled errors.
Unfortunately due to efficiency reasons I have to keep a large number of globals populated in order to do quick lookups. All commence 'glb' so I don't confuse them with locals.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top