Variables disappear before close

  • Thread starter Thread starter mmarch-at-direct-dot-ca
  • Start date Start date
M

mmarch-at-direct-dot-ca

Here is a strange observation about quiting Access 2000.
If you have code to run in the Unload or Close events
of the main form (switchboard):

(a) Using the Access menu Exit or window "X":
The code will run okay.

(b) Using a "Quit" command button on the main form:
Previously defined public or private variables will be gone!
The Unload and Close events fire, but string variables
to be used in these events are reduced to "".

The following VBA quit methods have been tried under the
Quit button, all with the same result:

Application.Quit
DoCmd.RunCommand acCmdExit
SendKeys "{F10}", True : SendKeys "F", True : SendKeys "X", True

So it seems any means of quitting Access from VBA code will
result in losing variables before you get a chance to use
them in the closing events.
 
You are correct. A 'soft' VBA reset occurs.
You can put the quit method as the last call on your switch board close /
unload code.
Failing that, you create a 'quitter' or custom application class and give it
a quit method (and any others required). The class runs all the cleanup-up
code prior to self destructing with a quit.


peter walker mvp
 
Back
Top