![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
|
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. |
#2
| |||
| |||
|
|
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 |
![]() |
| Thread Tools | |
| Display Modes | |
| |