Ms access MS Access-基于组合框值禁用标记控件

Ms access MS Access-基于组合框值禁用标记控件,ms-access,Ms Access,我想根据我在组合框中输入的值启用/禁用标记为“隐藏我”的所有字段 如果comboxox为yes,则应启用字段,如果没有字段,则应禁用字段 这是我的代码,目前它不起作用: Private Sub myAction_AfterUpdate() Dim frm As Form Dim ctl As Control Set frm = Forms!frmMyForm For Each ctl In frm.Controls If ctl.ControlType = acT

我想根据我在组合框中输入的值启用/禁用标记为“隐藏我”的所有字段

如果comboxox为yes,则应启用字段,如果没有字段,则应禁用字段

这是我的代码,目前它不起作用:

Private Sub myAction_AfterUpdate()

Dim frm As Form
Dim ctl As Control

Set frm = Forms!frmMyForm

    For Each ctl In frm.Controls

        If ctl.ControlType = acTextBox Or ctl.ControlType = acComboBox Then
            If ctl.Tag = "hideMe" Then
                If Me.myAction = yes Then
                    ctl.Enabled = True
                End If
            Else
                ctl.Enabled = False
            End If
        End If
    Next
End Sub
您缺少空格,无法比较字符串:

If ctl.Tag = "hide Me" Then
    If Me!myAction.Value = "Yes" Then

控件标记有不需要的字符串(见下图)以及
hideMe
标记
下图在即时窗口上显示了Debug.Print ctl.Tag的输出,以供快速参考

将控制标签设置为
hideMe
,然后运行此代码

Option Compare Database
Private Sub myAction_AfterUpdate()

Dim frm As Form
Dim ctl As Control

Set frm = Forms!frmMyForm

    For Each ctl In frm.Controls

        If ctl.ControlType = acTextBox Or ctl.ControlType = acComboBox Then


            If ctl.Tag = "hideMe" Then
                If Me.myAction = "yes" Then
                    ctl.Enabled = True
                 Else
                     ctl.Enabled = False
                 End If
            End If
        End If
    Next
End Sub

代码与隐藏项一起被错误复制

上述代码与附件中的代码完全相同。确保你没有在
myAction
combo上贴上“hideMe”标签。@Santosh谢谢你。是的,那是故意的。myAction组合没有标记。谢谢,我更新了代码,但这不起作用。项目被标记为“hideMe”,没有空格,并且我的操作的值应该是“yes”(或“no”,或用户想要输入的任何其他值)。
yes
不是字符串,而是未知变量<代码>“是”是一个字符串。谢谢@Santosh。这个确实有用。但是,你知道我的代码有什么问题吗?努力从我的错误中吸取教训。:)我从是改编了我的代码,看起来你无意中复制了整个代码以及控制下的隐藏标记。我不明白,抱歉;p我将“myAction”组合框的tag属性留空,并将另5个字段的tag属性设置为“hideMe”,如下所示。这不是它应该如何工作的吗?转到textbox控件=>打开属性=>其他选项卡=>将光标设置在
输入法句子模式上
倒数第二个属性=>按tab=>光标将移动到标记属性=>复制文本并粘贴到记事本上。现在就知道了。哦。非常感谢你!