How do I prevent a form from closing when the close button (X) is selected?
Posted on 2004-08-15
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.CancelEventArgs) 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
mWB = Nothing