When you want ot protect the form unload in accidently you can use this following code.
In this code, the action is When a form is prepared to unload The unload event was automatically raised on that event there is an parameter named “Cancel” which in the data type integer.
When the unload event is raised the “cancel” has the value as 0. If the value of “Cancel” is 0 the form is automatically unloaded. If we change the value to 1 the form was never end.
So I wrote the code as follows:
private sub form1_unload(Cancel as Integer)
a = MsgBox "Do u want to close?",vbYesNo,"Alert Message"
If a = vbYes Then
Cancel = 0
Else
Cancel = 1
End If
End Sub