IF condition - Show or Hide Textbox

Asked

Viewed 1,600 times

1

Expensive,

I have 4 optionButton (2 different groups), where 2 represent "Yes" and "No" for two different questions.

What I want to do:

When the user chooses the NO option in group1 and then chooses the YES option in Grupo2 a textobox is already displayed to explain why the answers are not equal (I can already do this).

And when it changes the group 1 option to YES, in Grupo2 you have to hide the textbox field.

Detail: optionButtons are in different multitabs*

Problem:

When the user is switching group option 1 to YES, he is not hiding the Grupo2 textbox.

Code to date:

Private Sub UserForm_Click()
If simSIMONI.Value = naoSISUP.Value Then
    motNaoSIMONI.Visible = True
    labMotNaoSIMONI.Visible = True
End If
End Sub
  • 1

    You put Visible as true... will not hide even false

  • 1

    You need to use the events of the option buttons themselves. In your code you are using the click on the form, which makes no sense.

  • @Andersonhenrique, this is one example. was a bad example of code

  • @Pedromvm I wish I didn’t have to put in all, because there are many. That’s why I tried to put right into the Form.

  • If there really are many Change Events, you can create a Change event class module in option Buttons within this Userform. It’s a bit more complex, but when an iterative user window is created with many buttons, this can make programming easier.

1 answer

1


Expensive,

Solved. I tried not to have to put validation on each optionbutton, but I couldn’t.

I put the validation on some optionButtons with if.

Example of the code

Private Sub simSISUP_Change()
If simSIMONI.Value = True And simSISUP.Value = True Then
    motNaoSIMONI.Visible = False
    labMotNaoSIMONI.Visible = False
End If
End Sub


Private Sub simSIMONI_Change()
If simSIMONI.Value = True And naoSISUP.Value = True Then
        motNaoSIMONI.Visible = True
        labMotNaoSIMONI.Visible = True
    Else:
        motNaoSIMONI.Visible = False
        labMotNaoSIMONI.Visible = False
End If
End Sub

Browser other questions tagged

You are not signed in. Login or sign up in order to post.