How do I let the user cancel closing the app? If they press the X button by accident and it says 'want to save, yes no cancel' for example.
Printable View
How do I let the user cancel closing the app? If they press the X button by accident and it says 'want to save, yes no cancel' for example.
VB Code:
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer) If (MsgBox("Are you sure?", vbYesNo) = vbNo) Then Cancel = True End If End Sub
Just a minor addition to tr0n's code:
VB Code:
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer) If DataUnsaved Then '<-- Check to see if the needs to be saved first If (MsgBox("Are you sure?", vbYesNo) = vbNo) Then Cancel = True End If End If End Sub