根据ms-access中的组合值隐藏/取消隐藏表单上的许多文本框(用户窗体)

时间:2019-02-16 22:32:44

标签: access-vba ms-access-2010

我目前有太多的if语句;编码隐藏和隐藏文本框的最佳解决方案是什么,我想我在这里有8个或更多组合,这是尝试此操作时的当前代码,它仅适用于最后一个if语句组合如下AD以及它们之间的所有组合。 :

If Combo308.Value = "A" Then
    Combo305.Visible = True
    Option103.Visible = True
    Else
     Combo305.Visible = False
    Option103.Visible = False
    End If


 If Combo308.Value = "B" Then
    Combo306.Visible = True
    Option105.Visible = True
    Else
    Combo306.Visible = False
    Option105.Visible = False
    End If


 If Combo308.Value = "D" Then
    Combo309.Visible = True
    Option111.Visible = True
    Text310.Visible = True
    Option113.Visible = True
    Combo311.Visible = True
    Option115.Visible = True
    Text312.Visible = True
    Option117.Visible = True
     Text313.Visible = True
    Option119.Visible = True
    Combo314.Visible = True
    Option121.Visible = True
    Text315.Visible = True
    Option123.Visible = True
    Text316.Visible = True
    Option125.Visible = True
    Text317.Visible = True
    Option127.Visible = True
     Text318.Visible = True
    Option129.Visible = True
     Text319.Visible = True
    Option131.Visible = True
    Else
    Combo309.Visible = False
    Option111.Visible = False
    Text310.Visible = False
    Option113.Visible = False
    Combo311.Visible = False
    Option115.Visible = False
    Text312.Visible = False
    Option117.Visible = False
    Text313.Visible = False
    Option119.Visible = False
    Combo314.Visible = False
    Option121.Visible = False
    Text315.Visible = False
    Option123.Visible = False
    Text316.Visible = False
    Option125.Visible = False
    Text317.Visible = False
    Option127.Visible = False
     Text318.Visible = False
    Option129.Visible = False
    Text319.Visible = False
    Option131.Visible = False
    End If

If Combo308.Value = "A,B" Then
    Combo305.Visible = True
    Option103.Visible = True
    Combo306.Visible = True
    Option105.Visible = True
    Else
     Combo305.Visible = False
    Option103.Visible = False
    Combo306.Visible = False
    Option105.Visible = False
    End If

If Combo308.Value = "A,B,C" Then
    Combo305.Visible = True
    Option103.Visible = True
    Combo306.Visible = True
    Option105.Visible = True
    Combo307.Visible = True
    Option109.Visible = True
    Else
    Combo305.Visible = False
    Option103.Visible = False
     Combo306.Visible = False
    Option105.Visible = False
    Combo307.Visible = False
    Option109.Visible = False
    End If

1 个答案:

答案 0 :(得分:0)

我想您首先需要隐藏所有控件,然后取消隐藏选择:

Combo305.Visible = False
Option103.Visible = False
' etc. - all controls in question.

Select Case Combo308.Value
    Case "A" 
        Combo305.Visible = True
        Option103.Visible = True
    Case "B" 
        Combo306.Visible = True
        Option105.Visible = True
    Case "D" 
        ' etc.
        '
    Case "A,B,C" 
        Combo305.Visible = True
        Option103.Visible = True
        Combo306.Visible = True
        Option105.Visible = True
        Combo307.Visible = True
        Option109.Visible = True
End Select

然后重命名所有控件以使用有意义的名称。