Compartir a través de


How to: Prompt a User Before Closing a Form

The following example illustrates how to prompt the user to verify that the form should closed.

Private Sub Form_Unload(Cancel As Integer) 
 If MsgBox("Are you sure that you want to close this form?", vbYesNo) = vbYes Then 
 Exit Sub 
 Else 
 Cancel = True 
 End If 
End Sub