dbTalk Databases Forums  

Re: Tip for trapping Access app close (special case)

comp.databases.ms-access comp.databases.ms-access


Discuss Re: Tip for trapping Access app close (special case) in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
MacDermott
 
Posts: n/a

Default Re: Tip for trapping Access app close (special case) - 07-29-2003 , 08:31 AM






Just a comment on your statement that Access closes forms in FIFO order -
Access forms are added to the Forms collection in the order in which
they are opened, yes.
If you step through that collection using
For i=0 to Forms.Count-1
you will run into trouble.
When Forms(0) is closed, the collection will be renumbered, and what had
been Forms(1) becomes Forms(0). The loop, however, will continue by closing
the new Forms(1), and the new Forms(0) will never get closed.

The standard solution is to loop backwards through your collection:
For i=Forms.Count-1 to 0 Step -1

BTW, someone told me once that
For Each frm in Forms
is tantamount to
For i=0 to Forms.Count-1
but I don't know how reliable that information is.

HTH
- Turtle

"Steve Jorgensen" <nospam (AT) nospam (DOT) nospam> wrote

Quote:
The standard technique for detecting when an Access application closes is
to
open a hidden form before anything else opens, and use the Form_Unload
handler
on that form to detect when the app is trying to shut down (Access closes
forms
in FIFO order). I just came up with a case where that's not quite enough
though.

My application uses a popup form as sort of a generic properties window
that
applies to several application forms. For efficiency, this form normally
does
not close, but traps the Form_Unload even, and sets Me.Visible = False to
hide
itself. That's fine except that, unless some mechanism is provided to set
a
flag telling the form to allow istelf to be truly closed when the app is
closed,
the form will never close, and neither will the application.

OK fine, you say - use the hidden form opened first as described above.
Unfortunately, that did not work when the other form is a popup. It seems
that
popup forms are unloaded before MDI forms even when the MDI forms were
loaded
first.

The solution, if it isn't obvious by now, is to make the hidden form
opened
first a popup form as well, so it takes precedence over other popup forms
as
well as MDI forms, reports, etc.



Reply With Quote
  #2  
Old   
Trevor Best
 
Posts: n/a

Default Re: Tip for trapping Access app close (special case) - 07-30-2003 , 02:26 AM






On Tue, 29 Jul 2003 09:31:56 -0400 in comp.databases.ms-access,
"MacDermott" <macdermott (AT) mindspring (DOT) com> wrote:

Quote:
Just a comment on your statement that Access closes forms in FIFO order -
Access forms are added to the Forms collection in the order in which
they are opened, yes.
If you step through that collection using
For i=0 to Forms.Count-1
you will run into trouble.
When Forms(0) is closed, the collection will be renumbered, and what had
been Forms(1) becomes Forms(0). The loop, however, will continue by closing
the new Forms(1), and the new Forms(0) will never get closed.

The standard solution is to loop backwards through your collection:
For i=Forms.Count-1 to 0 Step -1

BTW, someone told me once that
For Each frm in Forms
is tantamount to
For i=0 to Forms.Count-1
but I don't know how reliable that information is.

HTH
- Turtle
Easier to:

Do While Forms.Count
DoCmd.Close acForm Forms(0).Name
Loop

But obviously needs some checking in case a form refuses to close.

--
Ride Free (but you still have to pay for the petrol)

(replace sithlord with trevor for email)


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.