fowlow
asked on
How do I prevent a form from closing when the close button (X) is selected?
Hi,
I want to be able to prevent an application from closing if the user did not save their data correctly. e.g. they missed completing a field properly. I am using the form_Closing sub but when I call exit sub the application still terminates. How can I prevent this?
Private Sub myform_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.Canc elEventArg s) Handles MyBase.Closing
If mbSaveNeeded Then
If MsgBox("Save changes to current record?", MsgBoxStyle.Question.YesNo ) = MsgBoxResult.Yes Then
If Not DBSaveEntries() Then
Exit Sub THIS DOES NOT HELP BECAUSE THE FORM EXITS ANYWAYS
End If
End If
End If
mWB = Nothing
End
End Sub
I want to be able to prevent an application from closing if the user did not save their data correctly. e.g. they missed completing a field properly. I am using the form_Closing sub but when I call exit sub the application still terminates. How can I prevent this?
Private Sub myform_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.Canc
If mbSaveNeeded Then
If MsgBox("Save changes to current record?", MsgBoxStyle.Question.YesNo
If Not DBSaveEntries() Then
Exit Sub THIS DOES NOT HELP BECAUSE THE FORM EXITS ANYWAYS
End If
End If
End If
mWB = Nothing
End
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank-you very much.
Tim