Ms Access Hide and Show Fields based on combo box

2019-08-02 01:49发布

问题:

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?

回答1:

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