Cancel form close event (1 Viewer)

sloaner14

Registered User.
Local time
Today, 19:48
Joined
Apr 25, 2002
Messages
32
Is there a way to cancel a form's close event? If a user clicks the form's close button, I want a msgbox to ask if they are sure, and if yes continue and close, else cancel the forms close event. I know how to perform the msgbox and the if statement. I can not figure out how to cancel the form's close event.
 

WayneRyan

AWF VIP
Local time
Today, 19:48
Joined
Nov 19, 2002
Messages
7,122
Sloaner,

You might use the form's unload event:

Code:
Private Sub Form_Unload(Cancel As Integer)
  If MsgBox("Close?", vbYesNo) = vbYes Then
     Exit Sub
  Else
    Cancel = True
  End If
End Sub

Wayne
 

Users who are viewing this thread

Top Bottom