【问题标题】:Disabling specific controls on a form禁用表单上的特定控件
【发布时间】:2017-07-26 17:08:03
【问题描述】:

我已经翻遍了所有文档,甚至翻遍了文档,但我无法为一个看似简单的问题找到答案。

    Dim ctl As Control
For Each ctl In Me.Controls
    If ctl.ControlType <> acComboBox Then
        If ctl.Name <> "SrchVal" Then
            ctl.Enabled = False
        End If
    End If
Next ctl

我的表单上有大量用于数据输入的文本框控件。在单击某个按钮之前,它们都应该被锁定(禁用),这个事件我稍后会处理。

但是,我不想禁用一些组合框控件和一个文本框控件,标题为 SrchVal

我知道 Control 对象没有 Enabled 属性,我该如何解决这个问题?

【问题讨论】:

  • ctl!Enabled = False
  • 我收到以下运行时错误:Property let procedure not defined and property get procedure did not return an object
  • 你的代码有什么问题?
  • Ctl.Enabled = False 行出现错误
  • 表单上的某些控件是否可能没有 Enabled 属性?

标签: ms-access vba


【解决方案1】:

试试下面的代码:

Dim ctl As Control
For Each ctl In Me.Controls
    Debug.Print TypeName(ctl)
    If TypeName(ctl) <> "ComboBox" Then ' <-- check if control is not a Combo-Box
        Debug.Print ctl.Name
        If ctl.Name <> "SrchVal" Then
            ctl.Enabled = False
        End If
    End If
Next ctl

【讨论】:

  • 我在ctl.Enabled = False线上仍然收到错误消息
  • @Steven 我刚刚对其进行了全面测试并且运行良好,你能分享其余的 user_form 代码吗?
  • @Steven 尝试编辑代码,当您遇到错误时,让我知道您在即时窗口中得到了什么
  • Run-time error '438': Object doesn't support this property or method. 我将 Enabled 属性更改为 Visible 并且效果很好。
猜你喜欢
  • 2012-04-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-02
  • 1970-01-01
  • 2021-03-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多