Static Variables

ions

Access User
Local time
Yesterday, 21:45
Joined
May 23, 2004
Messages
816
Dear MS Access Expert.

Static variables don't see to hold their value after the end of execution.

I have a main function that is called using the MS Access form timer every 5 min.


This main function calls a second function multiple times that has Static variables. While executing the main, the Static Variables hold the data but once execution of the main is done they seem to lose the data for the next 5min cycle.

Will the same occur with global variables or do they store data as long as the .mdb is open? I expected the static variables to hold the data as long as .mdb is open.

Thanks
 
How did you declare the variables?

It should be

Static blnTest As Boolean

and it has to go in the procedure that uses it.
 
Oh, and also -

How are you modifying the values for the static variables? What code are you using?
 
SOS,

I figured out my confusion.

When execution is halted due to thrown error (i.e Err.Number & Err.Description) all global values are reset.

When execution completed smoothly the data in globals are maintained. I am assuming the same applies for Static Variables.
 
SOS,

I figured out my confusion.

When execution is halted due to thrown error (i.e Err.Number & Err.Description) all global values are reset.

When execution completed smoothly the data in globals are maintained. I am assuming the same applies for Static Variables.

Youi shouldnt lose variables with a handled error, I dont think.

But certainly, an unhandled error (with a debug/end message box) resets the variables
 
Just to re-iterate and maybe clarify, such variables and all objects in the project's memory are reset when your code is Stopped.
So when that Debug option pops up, if you choose Stop or Debug and then Stop the code - that's when you lose your variables.

It's actually a pretty narrow avenue considering how applications are generally shipped and so variables (including publicc ones) are more robust than they are often given credit for.

Cheers.
 

Users who are viewing this thread

Back
Top Bottom