Search Tools Links Login

Protect Form from Accidental Unloading


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

About this post

Posted: 2019-08-22
By: Arivoli
Viewed: 216 times

Categories

Visual Basic 6

Attachments

No attachments for this post

Special Instructions

This code originally appeared on AndreaVB.com, and has been republished here with the permission of Andrea Tincani.


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.