PDA

View Full Version : Saving variable after close program?



chris_uk_lad
08-19-2008, 01:26 AM
I have some VBA with a form that gives the user the option to close and return at a later stage (via a table that stores the recorded stage e.g you can type in your name, click exit, the button will remember that name has already been entered and progress to next stage.

My problem is that when the user comes back in, the variables have been emptied. Is there any way to store a variable within the code? I am using several modules if that helps.

OBP
08-19-2008, 02:37 AM
Do you mean that the user "Closes Access" or just closes the Form?
If it is just the Form did you declare the Variable as "Public"?

chris_uk_lad
08-19-2008, 03:36 AM
nope, mean when the uses closes the database (Access) then comes back in

CreganTur
08-19-2008, 05:19 AM
Access clears out all variables that are stored in system memory on Close.

So, if you want to keep your variable values then there's only one workaround I can think of- create a new table whose only purpose is to save these variable values. You'd need to run an update query on your form's on Close event to update the variable values to the table.

Then, when your user comes back to rework the account, you can use DLookup to grab the needed variable values.

BTW, noticed that you've corss-posted this topic at another site. There's absolutely nothing wrong with this, but please take a look at this article on cross-posting (http://www.excelguru.ca/node/7).

HTH:thumb

Carl A
08-19-2008, 06:22 AM
You can save your variable values to the registry by using SaveSetting and retrieve the values by using GetSetting. That is if you have access to the registry. If not Randy has the best alternative.(If not the better route):yes

CreganTur
08-19-2008, 06:38 AM
You can save your variable values to the registry by using SaveSetting and retrieve the values by using GetSetting.

That is awesome- I did not know you could read/write registry values with Access!

Window's help isn't very helpful on this subject- do you have any good resources on these methods?

Carl A
08-19-2008, 09:22 AM
No I don't have any resources other than help files VB and VBA which are almost word for word. I have included a small demo that is pretty basic. I included error trapping that catches a Invalid Procedure call when you try to access a non-existent key when using DeleteSetting . Also if you try to access a non-existent key when using GetSetting it will error with 13, type mismatch.

HTH