Ms Access Hide and Show Fields based on combo box choice

风流意气都作罢 提交于 2020-01-15 15:30:51

问题


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


来源:https://stackoverflow.com/questions/29893693/ms-access-hide-and-show-fields-based-on-combo-box-choice

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!