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

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
 
D

Danny J. Lesandrini

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
 
G

ghost

Hi Danny and Thank you for reply, what I want to do is making a Command
button!! is it possbile??
 
D

Danny J. Lesandrini

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
 
Top