How do I prevent a form from closing when the close button (X) is selected?
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
Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.