Cancel form close event (1 Viewer)

sloaner14

Registered User
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
Joined
Nov 19, 2002
Messages
7,091
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 (Users: 0, Guests: 1)

Top Bottom