Preventing Accesss from Closing

T

terri

My (2000 RT) application’s main screen form has code in the Unload event to
handle if the user "accidentally" clicks the X to close the application
instead of the X to close the current window. A message box asks if they
really want to exit, and cancels or continues accordingly. This works just
fine until…

I have situations where I need a report to run when one (or more) forms have
been opened modally using acDialog. To get around the problem of the report
displaying behind the forms instead of on top, I am using the idea from a
code sample by Terry Kreft: 1) loop through the Forms Collection and make
all the forms invisible; 2) display the report; and 3) when the report is
closed, make the forms visible again. This works just fine until…

If the user clicks the X to close the application instead of the X to close
the report window and answers "no" to the exit question, the main form's
Unload event code runs fine through to its exit sub point (the Cancel param
is set to true). Then the "Execution of this application has stopped due to
a run-time error" message displays. The Unload code then runs through a
second time. The application then shuts down regardless of the response.
BTW -- answering "yes" to the exit message originally, the application closes
just fine (without the runtime error).

I thought this may have something to do with the modal state of the forms,
but using the same "hiding" technique with only forms opened with acNormal,
results in the same behavior. Any insight?
 
T

terri

Thanks for your reply Alex.

Each routine does have error handling. BTW -- the application is set up in
such a way that I cannot simply step through code execution -- I have to add
message box indicators to determine checkpoints. I don't enter into any On
Error segments and once I reach the exit sub line of the Unload event, I
don't receive any further sign of a return to the prior functions -- I jump
right back to entering the Unload event a second time.

The problem seems to be the line of code to keep the report open until the
user specifically closes it:

Do While FormIsVisible(acReport, <Report Name>): DoEvents: Loop

Without this, the Unload event is fine. Of course without this, the open
forms aren't kept invisible defeating the whole purpose...

Are there any other options to have a report display on top of all the
current (even modal) forms? The Modal and Pop Up properties of the report
window seem to have no effect.
 
A

Alex Dybenko

Hi Terri,
don't know it there are more option to show report over modal/popup form,
then to hide it.
I think you can more checking if forms are still loaded while you access it
during close.
also you can consider inter of this:

Do While FormIsVisible(acReport, <Report Name>): DoEvents: Loop

use report close event


--
Best regards,
___________
Alex Dybenko (MVP)
http://accessblog.net
http://www.PointLtd.com
 
T

terri

Thanks again Alex.

The original hide/display code saved the forms afftected in an array -- that
way if any forms were invisible before the report was displayed, they
wouldn't be made visible after. However, since I really don't need to worry
about that, I put the (modified) show code in the report's close event and
all is well.
 

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