optimist khan
optimist khan

Reputation: 11

Ms Access Hide and Show Fields based on combo box choice

I have a Userform in Access. In my Userform I have a ComboBox with 3 option: A, B and C. Based on there values, I would like to hide/unhide Text boxes. This is the scenario:

When i select A i want to automatically do the following. * Show text box 1 * Hide text box 2

When B * Hide textbox 1 * Show textbox 2

When C * Show textbox 1 * Show textbox 2

How can this be done?

Upvotes: 1

Views: 8313

Answers (1)

PaulFrancis
PaulFrancis

Reputation: 5819

What you want is to make use of the After Update event of the ComboBox, which will say the logic of what needs to be done when. Something like,

Private Sub comboBoxName_AfterUpdate()
    Select Case Me.comboBoxName
        Case "A"
            Me.textBox1Name.Visible = True
            Me.textBox2Name.Visible = False
        Case "B"
            Me.textBox1Name.Visible = False
            Me.textBox2Name.Visible = True
        Case Else
        'Case "C" is also valid
            Me.textBox1Name.Visible = True
            Me.textBox2Name.Visible = True
    End Select
End Sub

Upvotes: 2

Related Questions