Exiting Access

J

j_gold

Hi,

I have the following in my unload event. I have a button on a form that when
clicked, prompts the user if they want to exit the application (I've disabled
the form's close button so this is the only way to exit the program). If they
click yes, the application should close without further ado, however, the
message asking them to quit appears twice - on the second click of yes, the
application then quits.

The unload event is firing twice. How best to do this?

Thanks, J

Private Sub Form_Unload(Cancel As Integer)

If MsgBox("Exit Application?", vbYesNo) = vbYes Then
DoCmd.Quit
Else
Cancel = True
End If

End Sub
 
D

Dale Fye

What is the code in the Click event of the button?

My guess is that you have similar code in the click event and in the forms
unload event.
 
J

j_gold

Hi Dale, this is what I have for the Click event of my close button. ~ J


Private Sub exitApplication_Click()

Form_Unload 0

End Sub
 
J

Jack Leach

It may also be that the Unload is actually firing twice because of the
placement of your messagebox....

From the Unload event, you are using Appplication.Quit, before the Unload
event finishes. What may be happening is that the current Unload is put on
hold while the app runs through it's Quit procedure (seeing that the form is
not yet unloaded, therefore firing the event yet again).

I'm not sure of this, but it may be worth a try to put the code in a
different event.
--
Jack Leach
www.tristatemachine.com

"I haven't failed, I've found ten thousand ways that don't work."
-Thomas Edison (1847-1931)
 
J

j_gold

Thanks Jack. That's what I figured too.

I removed the form's unload and close events and changed the Click event to
below. Seems to have done the trick.

Private Sub exitApplication_Click()

If MsgBox("Exit Application?", vbYesNo) = vbYes Then
DoCmd.Quit
Else
DoCmd.OpenForm "Switchboard"
End If

End Sub


Cheers, J
 

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