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!

Storing a Variable Passed Out of Scope

Status
Not open for further replies.

sdk

Technical User
Aug 20, 2000
177
AU
I would like to store a variable (ie within a module) so that the value is writable, and the new value will be available the next time I need it, regardless if the database has been closed.

This would be an extension of the static variable type, but with the updated value stored/retrieved as the variable is passed out of scope or the module is called. From what I can see so far, this may mean writing to & reading a single variable to file. If so, how is this done?

And lastly, is there an equivalent to autoexec to automatically call methods etc when the database is closed?

Cheers & thanks
 
For variable initialization I tend to use a hidden form in the background when the database opens, and I keep the form opened throughout the application. You can open the form either with the initial AutoExec macro or from a procedure called from the AutoExec macro.

The reason for using a hidden form is that you can use the OnOpen and OnClose events to perform your initializations and save the values before the database closes.

Create the form that will contain the initialization and closing routines.

In the Macro for OpenForm, use the Window Mode: Hidden.

From the Main Toolbar, you can access (and possibly restrict access) the hidden form with Window..Unhide.

From a global procedure, use the following command.

DoCmd.OpenForm <formName>, , , , , acHidden

Hope this helps.

Scott.
 
Hi, an easy way is to use a global variable and write the variable to the global variable once the variable is known.
This will remain for the life of the programme. If you need to temporarily look at the value of the variable you can assign a text box to the global.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top