DoCmd.Quit in Form OnClose leads to error

  • Thread starter rdemyan via AccessMonster.com
  • Start date
R

rdemyan via AccessMonster.com

I have a form with a close button on it. When the close button is clicked I
want the entire application to close.

In the Form_Close event I have code that does some cleanup and then uses
DoCmd.Quit (I've also tried Application.Quit) to shut down the application.

In the close button click event I have the following line of code:

Call Form_Close

When I click the 'X' on the form control box, everything closes just fine.
I've walked through the code and doing this definately causes the Form_Close
event to be executed.

When I click on the Close button on the form (not in the control box), the
Form_Close event gets called and the code is executed. However, when DoCmd.
Quit (or Application.Quit) is encountered an error occurs:

"Invalid Procedure Call or Argument"

But the app shuts down anyway after the message box with the error message is
closed.

So to sum up, the Control Box 'X' works fine, but a 'Close' button on the
form leads to this error. Presumably both use the exact same code to clean
up and then close the app.

Any ideas???
 
R

RoyVidar

rdemyan via AccessMonster.com wrote in message said:
I have a form with a close button on it. When the close button is
clicked I want the entire application to close.

In the Form_Close event I have code that does some cleanup and then
uses DoCmd.Quit (I've also tried Application.Quit) to shut down the
application.

In the close button click event I have the following line of code:

Call Form_Close

When I click the 'X' on the form control box, everything closes just
fine. I've walked through the code and doing this definately causes
the Form_Close event to be executed.

When I click on the Close button on the form (not in the control
box), the Form_Close event gets called and the code is executed.
However, when DoCmd. Quit (or Application.Quit) is encountered an
error occurs:

"Invalid Procedure Call or Argument"

But the app shuts down anyway after the message box with the error
message is closed.

So to sum up, the Control Box 'X' works fine, but a 'Close' button on
the form leads to this error. Presumably both use the exact same
code to clean up and then close the app.

Any ideas???

I think that calling the Form_Close event, will execute (or try to)
execute the code in that event, not close the form. To close the form,
try

DoCmd.Close acform, me.name

instead. This will trigger the on close event of the form when it
reaches that step in the sequence of events when closing the form.
Whether or not the form closes, and also the application, will perhaps
depend on whether it is in a state which allows it to close.
 
R

rdemyan via AccessMonster.com

Yes, yes, that worked nicely. So by using DoCmd.Close acform, me.name, the
Form OnClose event was fired, which accomplished the clean up required and
also closed the application.

Thanks!
rdemyan via AccessMonster.com wrote in message said:
I have a form with a close button on it. When the close button is
clicked I want the entire application to close.
[quoted text clipped - 26 lines]
Any ideas???

I think that calling the Form_Close event, will execute (or try to)
execute the code in that event, not close the form. To close the form,
try

DoCmd.Close acform, me.name

instead. This will trigger the on close event of the form when it
reaches that step in the sequence of events when closing the form.
Whether or not the form closes, and also the application, will perhaps
depend on whether it is in a state which allows it to close.
 

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

Similar Threads


Top