DiverDan
Contributor
Hi, I'm calling a checkSave sub prior to the closing of Form1. The checkSave sub creates a yes, no, cancel message box and from the button selection sets a boolean value on varaible continue.
Code is:
This works well with every part of the program except for the Form1 close button "X". I wrote a closing sub for Form1 closing with the code:
The problem is that the form closes when the message box cancel button is chosen and continue = False. Why?
Thanks
Code is:
Visual Basic:
Sub checkSave()
If worksheetModified = True Then
Dim responce As MsgBoxResult
responce = MsgBox("Do you want to save changes to " & StatusWorksheet.Text & " ?", MsgBoxStyle.YesNoCancel, Me.Text)
If responce = MsgBoxResult.Cancel Then
continue = False
ElseIf responce = MsgBoxResult.No Then
worksheetModified = False
continue = True
ElseIf responce = MsgBoxResult.Yes Then
mnuSaveAs.PerformClick()
worksheetModified = False
continue = True
End If
End If
End Sub
Visual Basic:
Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
checkSave()
If continue = False Then Exit Sub
If continue = True Then MyBase.Dispose()
End Sub
Thanks
Last edited by a moderator: