Stop Button

  • Thread starter Thread starter Neil Greenough
  • Start date Start date
N

Neil Greenough

I have included a stop button on a form to exit a database. The code for
this is

Private Sub QuitApplication_Click()
On Error GoTo Err_QuitApplication_Click


DoCmd.Quit

Exit_QuitApplication_Click:
Exit Sub

Err_QuitApplication_Click:
MsgBox Err.Description
Resume Exit_QuitApplication_Click

End Sub


I want it so that, when it is clicked, a message box appears saying "Are you
sure you want to exit?" With a yes or no answer.

Anybody able to edit my code for me pretty please with jelly tots?
 
Hi Neil,

if Msgbox("Are you sure you want to
exit?",vbyesno+vbquestion,"Confirmation")=vbyes then
docmd.quit
end if

should do the trick....
 
Thanks Alex.

Where about should I be adding that additional code? At the beginning of the
original code or.....? Do I need to delete anything from the original code?
 
Hi Neil,

just wrap the

if msgbox....

end if

around the code you want to run under that condition.

e.g

Private Sub QuitApplication_Click()
On Error GoTo Err_QuitApplication_Click

if Msgbox("Are you sure you want to
exit?",vbyesno+vbquestion,"Confirmation!")=vbyes then
DoCmd.Quit
end if

Exit_QuitApplication_Click:
Exit Sub
Err_QuitApplication_Click:
MsgBox Err.Description
Resume Exit_QuitApplication_Click
End Sub

Does that answer your question?

you may want to try either of these as they may save you being prompted on
other issues when closing.


DoCmd.Quit acQuitSaveAll

DoCmd.Quit acQuitSaveNone
 
Alex,

It works a treat! Thanks!

Neil

Alex White MCDBA MCSE said:
Hi Neil,

just wrap the

if msgbox....

end if

around the code you want to run under that condition.

e.g

Private Sub QuitApplication_Click()
On Error GoTo Err_QuitApplication_Click

if Msgbox("Are you sure you want to
exit?",vbyesno+vbquestion,"Confirmation!")=vbyes then
DoCmd.Quit
end if

Exit_QuitApplication_Click:
Exit Sub
Err_QuitApplication_Click:
MsgBox Err.Description
Resume Exit_QuitApplication_Click
End Sub

Does that answer your question?

you may want to try either of these as they may save you being prompted on
other issues when closing.


DoCmd.Quit acQuitSaveAll

DoCmd.Quit acQuitSaveNone


--
Regards

Alex White MCDBA MCSE
http://www.intralan.co.uk
 
Back
Top