I came across an interesting issue:
I have a userform with various comboboxes and text boxes and each of these boxes has this simple code:
Private Sub CustomerBox_Change()
ChangesDetected = True
End Sub
(btw ChangesDetected is publicy declared as a boolean)
The code below executes once the userform is closed and if ChangesDetected = True then the code prompts the user with a message box.
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
Windows("LorecsDataBase").Visible = True
If ChangesDetected = False Then
DataBaseWb.Close False
Exit Sub
ElseIf ChangesDetected = True Then
If CanUndo Then
Dim strPrompt As String
Dim strTitle As String
Dim iRet As Integer
strPrompt = "Changes were made to this contact. Would you like to close without saving?"
strTitle = "Message"
iRet = MsgBox(strPrompt, vbYesNo, strTitle)
If iRet = vbNo Then
Cancel = True
End If
If iRet = vbYes Then
DataBaseWb.Close False
End If
End If
End If
With Application
.EnableEvents = True
.ScreenUpdating = True
.Calculation = xlCalculationAutomatic
End With
End Sub
Now comes the interesting part; if i close the userform via a custom close button that uses "unloadme" the code works fine, but if i close the userform via the the top right "X" the code will process the boolean variable. How do i know that the code is ignoring it? That;s because if i put a random message box at the beginning then if i click on the "X" the msgbox will show. For some reason the "X" is ignoring the boolean.
I would really appreciate any help on this.
Thanks in advance!
Bookmarks