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

How to initialise a permanent variable

Status
Not open for further replies.

metaltree

Technical User
Nov 27, 2006
28
0
0
CA
Is there a way to declare and initialise a variable on a form that retains its value even when that form is closed and reopened ?
 
If you want to do that you'd have to store the value you want (in a table, the registry or a config file for example) and then assign the variable that value at runtime.

Hope this helps

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
Do as HarleyQuinn says if you want to persist values between sessions.

If you are just concerned about preserving a variable's value within the same session then define your variable as PUBLIC in a module.

It is then available regardless of which forms are, or are not, open.

 
Okay, thanks for your quick and helpful comments.
 
How are ya metaltree . . .

I'm surprised no one mentioned setting up your own [blue]Custom Db property![/blue] Custom Db properties are read/write [purple]non-volitile[/purple], and can save resources otherwise taken by a new table.

[blue]Your Thoughts? . . .[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
Do you have any links for this theaceman1?

You can also dim a global variable but this IS volitile and ceasts existance once the database is closed.

MetalTree, as a matter of interest what do you want to use it for?


Ian Mayor (UK)
Program Error
Your lack of planning is not my emergency!
 
Howdy ProgramError . . .

See my post here thread702-1236022

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
metaltree . . .

See the link in my prior post. [blue]Custom DB properties[/blue] like access properties, maintain their values even if the Db is closed!

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
Hey guys,

I have started using GetSetting and SaveSetting instead - this saves the items to the Windows Registry for later use.

I have found this handy for features like program environment customisation.

Code:
SaveSetting "ProgramName","SubKeyName","Property",Value

and:

Code:
envSetting1 = GetSetting("ProgramName","SubKeyName","Property")


HTH :)
 
Just to quickly elaborate on where the registry settings are saved too:

HKEY_CURRENT_USER/Software/VB and VBA Program Settings/ProgramName/
 
To All! . . .

With so many options available in one thread, I wonder, [blue]what happen to metaltree! [surprise] . . .[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
Hello all,

sorry for the late reply.

I stored the variable into a table finally, and it worked.

I used it to store the path and filename chosen by the user with the .FileDialog(msoFileDialogFilePicker) method.

Many thanks,

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top