2017-07-26 47 views
0

我已经查看了所有内容,甚至查看了文档,并且无法找到看似简单问题的答案。禁用表单上的特定控件

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属性,所以我该如何解决这个问题?

+0

CTL启用=假 –

+0

我收到以下运行时错误:'Property Let过程没有定义,属性获取过程未返回object' – Steven

+0

问题是什么用你的代码? –

回答

0

尝试下面的代码:

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 
+0

我仍然收到一条错误'ctl.Enabled = False' – Steven

+0

@Steven我刚刚测试过它,它运行良好,你可以分享其余的user_form代码? –

+0

这是窗体加载事件中唯一的代码 – Steven

相关问题