Ask For Confirmation Before Exit Progarm

When the user will try to end this program by clicking the X button, by pressing Alt + F4, or by any other way, a message box will pop up and will ask him for confirmation.

Form Code

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
  Dim Answer As Integer
   Answer = MsgBox("Are you sure you want to exit this program?", _
   vbQuestion + vbYesNo, "Confirmation")
   If Answer = vbNo Then Cancel = -1
End Sub

Go Back