基于ms-access中的组合值隐藏/取消隐藏表单上的许多文本框(userform)

问题描述 投票:0回答:1

我目前有太多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
access-vba ms-access-2010
1个回答
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

并重命名所有控件以获得有意义的名称。

© www.soinside.com 2019 - 2024. All rights reserved.