Shutdown anomaly

T

TedMi

My application opens a series of forms, all non-modal; most have a Form_Load
procedure. Everything works fine, except in this one case: If the series of
forms is open and Access is shut down by closing the top-level window or by
executing a Quit command, one form’s Load procedure runs during the shutdown
process, showing all sorts of error messages, because resources needed by the
load event are being or have been shut down.
This happens most of the time, but not consistently (indicating perhaps a
timing dependency or race condition?), and appears in both 2002 and 2003
versions. Inserting DoEvents did not help. Has anyone seen this before? What
might cause it?
I solved this by moving the offending form’s startup code from the Load to
the Open event, and that cleared it up, but that avoids the symptom instead
of providing a cure. Any thoughts?
 
D

Dirk Goldgar

TedMi said:
My application opens a series of forms, all non-modal; most have a
Form_Load procedure. Everything works fine, except in this one case:
If the series of forms is open and Access is shut down by closing the
top-level window or by executing a Quit command, one form's Load
procedure runs during the shutdown process, showing all sorts of
error messages, because resources needed by the load event are being
or have been shut down.
This happens most of the time, but not consistently (indicating
perhaps a timing dependency or race condition?), and appears in both
2002 and 2003 versions. Inserting DoEvents did not help. Has anyone
seen this before? What might cause it?
I solved this by moving the offending form's startup code from the
Load to the Open event, and that cleared it up, but that avoids the
symptom instead of providing a cure. Any thoughts?

Could it be that the Close or Unload event of some other form has code
in it that opens the form that's causing the trouble?
 
T

TedMi

Dirk: Thanks; I checked, and there is no code in any unload or close event. I
tracked it down in more detail: there is a startup formMain which controls
all the app functions. If this form has been autoloaded and is open when the
the app shuts down; the following sequence of events occurs:
formMain Unload
formMain Close
formLast Load
main window closes
where formLast is the last form to be opened, via a chain of UI actions that
begins on formMain. This created a problem on only one form, where the load
event was referencing controls on formMain. All other load events are local
to their forms. Note that the Open event is not fired – hence my workaround.
However, if formMain is opened manually, or is closed prior to shutdown, or
other forms were opened from the db window, then the anomalous Load event
does not fire on shutdown. Is that wierd or what? Debugging is not possible,
because breakpoints are not honored in code executing during app shutdown, so
I'm tracing with MsgBoxes.
I will try to rebuild formMain to see if that helps.
 
D

Dirk Goldgar

TedMi said:
Dirk: Thanks; I checked, and there is no code in any unload or close
event. I tracked it down in more detail: there is a startup formMain
which controls all the app functions. If this form has been
autoloaded and is open when the the app shuts down; the following
sequence of events occurs: formMain Unload
formMain Close
formLast Load
main window closes
where formLast is the last form to be opened, via a chain of UI
actions that begins on formMain. This created a problem on only one
form, where the load event was referencing controls on formMain. All
other load events are local to their forms. Note that the Open event
is not fired - hence my workaround. However, if formMain is opened
manually, or is closed prior to shutdown, or other forms were opened
from the db window, then the anomalous Load event does not fire on
shutdown. Is that wierd or what? Debugging is not possible, because
breakpoints are not honored in code executing during app shutdown, so
I'm tracing with MsgBoxes.
I will try to rebuild formMain to see if that helps.

That's very odd, and I'm at a loss to explain it if there's no code
anywhere along the way that would open the last form again. You're
saying it's always the last form loaded whose load event fires at
shutdown, but it's not always the same form? I see your forms aren't
opened modal, and I suppose they aren't opened in dialog mode; are they
popup?

The fact that it only happens when formMain was opened automatically
makes it look a lot more like a bug. Is formMain initially opened by
the Startup "Display Form/Page" property, or do you use an autoexec
macro?

You might try making a copy of the database, decompiling it, compacting
it, and recompiling it to see if that makes a difference.
 
T

TedMi

The main form opens by virtue of being in the startup properties. There is an
Autoexec macro, but it only reconnects to the back end and does no form
manilupation. All of the forms open in non-modal, non-popup, non-dialog mode.
Yes, verrrry strange.
I solved it by recreating formMain - copied all of the controls and code to
a new form (I learned long ago to put heavy-duty event code in modules, with
just calls in the event procs of the form!) The firing of the spurious Load
event went away. Go figure.
Thanks for your time.
 
D

Dirk Goldgar

TedMi said:
The main form opens by virtue of being in the startup properties.
There is an Autoexec macro, but it only reconnects to the back end
and does no form manilupation. All of the forms open in non-modal,
non-popup, non-dialog mode. Yes, verrrry strange.
I solved it by recreating formMain - copied all of the controls and
code to a new form (I learned long ago to put heavy-duty event code
in modules, with just calls in the event procs of the form!) The
firing of the spurious Load event went away. Go figure.
Thanks for your time.

Thanks for sharing an interesting phenomenon. I've never heard of that
one before. I'd guess it's some sort of corruption, but that's only a
catch-all sort of guess.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top