sujittalukde
02-04-2012, 03:37 AM
This is the code I am using for unloading the user form. The button is named as cmdExit.
Private Sub cmdExit_Click()
Dim Smsg As String
Smsg = "Are you really want to exit? Click Yes to terminate or No to Continue."
If MsgBox(Smsg, vbYesNo + vbDefaultButton2 + vbQuestion, "Exit!") = vbYes Then
Unload Me
End If
End Sub
now if the user clicks the cross "X" button on User form title bar, the form unloads without the warning message as set out in the exit button. So I put the following code:
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
Cancel = True
Call cmdExit_Click
End If
End Sub
Now the warning message is coming but the user form does not unload if the "Yes" option is clicked in the warning message.
How to overcome the issue?
Private Sub cmdExit_Click()
Dim Smsg As String
Smsg = "Are you really want to exit? Click Yes to terminate or No to Continue."
If MsgBox(Smsg, vbYesNo + vbDefaultButton2 + vbQuestion, "Exit!") = vbYes Then
Unload Me
End If
End Sub
now if the user clicks the cross "X" button on User form title bar, the form unloads without the warning message as set out in the exit button. So I put the following code:
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
Cancel = True
Call cmdExit_Click
End If
End Sub
Now the warning message is coming but the user form does not unload if the "Yes" option is clicked in the warning message.
How to overcome the issue?