1

In my Access database I have a global variable (Global allowEditing as Boolean) defined in a module (Main). I set this variable, then I want to use it later at the form level to disable some buttons. I'm having trouble with this.

For Each ctl In Me.Controls
    ctl.Enabled = False            'Works for True or False            
    ctl.Enabled = allowEditing     'Throws error               
  Next

The error thrown is:

Run-time error '438': Object doesn't support this property or method.

Whats happening here and how can I use the boolean value?

4

3 回答 3

3

当您尝试设置不存在的属性(如为标签控件启用)时,会发出错误 438。

尝试这个

For Each ctl In Me.Controls
  If TypeOf ctl Is TextBox Then
    ctl.Enabled = False            'Works for True or False
    ctl.Enabled = allowEditing     'Throws error
  End If
Next
于 2012-11-02T17:43:20.583 回答
1

每个控件都有一个ControlType属性。您可以利用该属性仅禁用您从支持该Enabled属性的控件中选择的那些。此过程将设置Enabled复选框、组合、列表框和文本框的属性。

For Each ctl In Me.Controls
    With ctl
        Select Case .ControlType
        Case acCheckBox, acComboBox, acListBox, acTextBox
            .Enabled = allowEditing
        Case Else
            ' pass
        End Select
    End With
Next
于 2012-11-02T19:17:55.947 回答
1

听起来像一个范围问题。如果你想在多个表单之间全局使用这个布尔值,我建议创建一个 Access 表来保存全局状态变量。只需对表运行查询以获取值。

于 2012-11-02T17:28:21.050 回答