Store a variable once form is closed

clive2002

Registered User.
Local time
Today, 05:08
Joined
Apr 21, 2002
Messages
91
I'm trying to set a variable in a form and store the value for use in other forms even after the initial form is closed.

I don't wont to write to a table and i think this can be achieved using a static declaration in a class module, but am unsure how to do this?

Any help greatfully recieved.
 
Inside a standard module declare the variablr youwant to retain

Public StrVariableName As String

Then refer to that in your form.
 
but note that if your programme crashes with any unhandled error, your stored value will clear to a space, or zero
 
There's no indication, that I can see, of the version of Access here.
If this is 2007 or newer, then you can easily use the TempVars collection.

Whenever you want
TempVars("MyValue") = varSomething

Whenever you subsequently want to retrieve it just reference it
varSomething = TempVars("MyValue")

You can make a manual equivalent if you want in earlier versions - but it's maybe less worthwhile.

Cheers.
 
Thanks,

I'll try both suggestions and see which works best for me.
 
Not to labour this old point - but to address the
>> if your programme crashes with any unhandled error, your stored value will clear to a space, or zero

That requires a very particular scenario.
You'd have to have an application which allows code to be halted. i.e. you'd need to be distributing an MDB/ACCDB and not an MDE/ACCDE and a retail installation of Access. Anything else either would cause the application to exit compeltely on an unhandled error (a variable's value obviously doesn't matter then by comparison ;-) or it would cause no inherent problem upon the unhandled error (i.e. it would recover and march onwards - your variable values still intact, if an MDE/ACCDE).

Cheers.
 

Users who are viewing this thread

Back
Top Bottom