Protect Form from Accidental Unloading
Posted: 2019-08-22
By: Arivoli
Viewed: 183
Filed Under:
VB6 Custom Controls/Forms/Menus, VB6 Miscellaneous, VB6 Code Cache
No attachments for this post
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
Special Instructions
This code originally appeared on AndreaVB.com, and has been republished here with the permission of Andrea Tincani.
Comments on this post
No comments have been added for this post.
You must be logged in to make a comment.