Is there a way to tell why a form is closing?

M

Max Moor

Hi All,

I keep a left side navigation form open all the time in my app. On it
is a list of all the open forms in the remaining MDI space. When a new form
is opened, it adds itself to that list. When the user closes the form, it
removes itself.

The list is really a listbox tied to a table with all the forms that
might be open listed. A Yes/No field tracks if the form is open or not. The
intent was to have this table remember what was open, and have the left-nav
form reopen the last open forms each time the app starts.

I stuck the remove-from-list call in the forms' close events.
Unfortunately, these fire as the app shuts down, so the list is always
emptied, and the app always opens with and empty forms space.

What event or other mechanism can I use to tell the difference between
the user closing the form with a close button, and the form just closing
because the app is exiting?

Regards,
Max
 
S

Steve Sanford

In most of my forms, the only way to close a form is to click on a"Close"
button.


First, in the form properties, on the FORMAT tab, set the "Close button"
property to NO.

Then add a button control to the form. Name it "btnClose". For the click
event, add this:

Private Sub btnClose_Click()
' your code to remove-from-list call goes here
' remove-from-list (or whatever you call it)

DoCmd.Close acForm, Me.Name
End Sub


Now the remove-from-list call only runs when the button is clicked :D


HTH
 
M

Max Moor

In most of my forms, the only way to close a form is to click on
a"Close" button.


First, in the form properties, on the FORMAT tab, set the "Close button"
property to NO.

Then add a button control to the form. Name it "btnClose". For the click
event, add this:

Private Sub btnClose_Click()
' your code to remove-from-list call goes here
' remove-from-list (or whatever you call it)

DoCmd.Close acForm, Me.Name
End Sub


Now the remove-from-list call only runs when the button is clicked :D


HTH

Hi Steve,

Thanks for the reply. Sorry I didn't cover the whole story better.
I'm actually doing what you suggest in a couple of forms now, but I
don't want to. What I have is an app where all open forms maximize
into the entire MDI space. Currently, I use an 'X' label with an
OnClick event that does as you suggested. What I really wanted was
for the system close button to be available in the menu bar (standard
maximized form stuff), but be able to trap that click, or something.
Effectively, I want to tell the difference between a
system-close-button-close and a close for any other reason.

Regards,
Max
 
S

Steve Sanford

Max,

I did some searching...there are some examples of using APIs with forms on
"The Access Web" (mvps.org/access/api/index.html).... mostly changing form
size.
Maybe you could develop something from the examples. For me, its like the
joke about the roof......... It's (API programming) way over my head! :p

I use the button code because it is easy and I can modify it. I have a
template form with my form design - the close button is one control I have on
the template. It is quicker to delete it than recreate it on new forms.


Anyway, sorry I couldn't help you.
 
M

Max Moor

Max,

I did some searching...there are some examples of using APIs with forms
on "The Access Web" (mvps.org/access/api/index.html).... mostly changing
form size.
Maybe you could develop something from the examples. For me, its like
the joke about the roof......... It's (API programming) way over my
head! :p

I use the button code because it is easy and I can modify it. I have a
template form with my form design - the close button is one control I
have on the template. It is quicker to delete it than recreate it on
new forms.


Anyway, sorry I couldn't help you.

Hi Again Steve,

I think I'm going to stick with the same thing. the little x label
looks just like the real thing, and as you say, I can control it easily.
The only real difference is that it's in the form space and not the menu
bar space. The only person that is ever going to care is the anal
retentive developer that put it there. :)

At any rate, I appreciate your replies. Even if I didn't get the
answer I hoped for, it's good to have a second opinion on things.

Regards,
Max
 

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