DBraun
DBraun

Reputation: 38

Multiple UserForms that trigger each other; UserForm_QueryClose not working as expected

I've got 5 UserForms and some of them activate depending on what the input of the first UserForm is.

The first UserForm code is below.

Private Sub OptionButton1_Click()

    If OptionButton1.Value = True Then
        WsName = "CAT"
        Unload Me
    End If
End Sub

Private Sub OptionButton2_Click()
    If OptionButton2.Value = True Then
        WsName = "DOG"
        Unload Me
    End If
End Sub

Private Sub OptionButton3_Click()
    If OptionButton3.Value = True Then
        WsName = "CATDOG"
        Unload Me
    End If
End Sub

Private Sub OptionButton4_Click()
    If OptionButton4.Value = True Then
        WsName = "DOGCAT"
        Unload Me
    End If
End Sub

Private Sub UserForm_Initialize()
    Me.StartUpPosition = 0
    Me.Top = Application.Top + 250
    Me.Left = Application.Left + Application.Width - Me.Width - 600
End Sub

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
    End
End Sub

When I press the Red "X" to end the entire module that calls the UserForm the module is exited and I am happy. When I press one of the options on the userform like OptionButton1.Value = True then the code also exits the module and I am sad. What am I doing wrong? I would like for the user to be able to press the Red "X" at any point in any UserForm to close out the Module and break out of the code.

Upvotes: 0

Views: 88

Answers (1)

DBraun
DBraun

Reputation: 38

The answer to this question was

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
   If 
      OptionButton1.Value = False And OptionButton2.Value = False OptionButton3.Value = 
      False And OptionButton4.Value = False Then 
      End 
  End If 
End Sub 

Upvotes: 0

Related Questions