How to alert the user if he wants to exit the program

  • Thread starter Thread starter ghost
  • Start date Start date
G

ghost

hi,

is there any code that alert the user on exiting the progam with the
message" Are you sure you want to exit the Program?"

Thank you
 
That depends on which form(s) you have open. Some people keep a hidden form
around for just such a condition. Alternatively, you might ask the question when the
menu form is closed. Put this code on the form's Unload event


Private Sub Form_Unload(Cancel As Integer)

If MsgBox ("Are you sure you want to exit the Program?", vbYesNo, "Exit?") = vbNo Then
Cancel = False
End Sub
 
Hi Danny and Thank you for reply, what I want to do is making a Command
button!! is it possbile??
 
Well, that's even easier.

Private Sub cmdClose_Click()

If MsgBox ("Are you sure you want to exit the Program?", vbYesNo, "Exit?") = vbNo Then
' do nothing
Else
DoCmd.Close acForm, Me.Name
End Sub
 
Back
Top