【问题标题】:MS Access - Creating a generic Sub to set Properties of controls on a SubformMS Access - 创建通用 Sub 以设置子窗体上的控件属性
【发布时间】:2021-06-21 18:52:13
【问题描述】:

我有一个可以从任何表单调用的通用 Sub,它将启用所有将 Tag 属性设置为“EnableForReadOnly”的文本框和组合框。我想为 Subforms 创建类似的东西。

    Public Sub EnableReadOnlyControls(theForm)

Dim i As Integer
' Cycle through the form's controls,

For i = 0 To theForm.Count - 1
    If theForm(i).Tag = "EnableForReadOnly" Then
        If TypeOf theForm(i) Is TextBox Then
            theForm(i).Locked = False
            theForm(i).Enabled = True
        ElseIf TypeOf theForm(i) Is ComboBox Then
            theForm(i).Locked = False
            theForm(i).Enabled = True
        End If
    End If
Next i

结束子

要从表单调用这个 Sub,在表单的 OnOpen 事件上,我输入以下内容,效果很好:

EnableReadOnlyControls Me

我想为子表单创建一个类似的通用 Sub,但我不确定是否可以以这种通用方式引用子表单。任何想法将不胜感激。

【问题讨论】:

  • 您可以简单地使用相同的功能。 EnableReadOnlyControls Me.SubformControl.Form。或者您在子表单的 Open 事件中的呼叫。
  • 感谢@Andre 完美运行!

标签: ms-access reference subform


【解决方案1】:

我在这里重新发布安德烈的评论作为答案。谢谢安德烈!

“您可以简单地使用相同的函数。EnableReadOnlyControls Me.SubformControl.Form。或者您在子表单的 Open 事件中的调用。”

示例:我的主窗体上的子窗体控件的名称是 frmCounterTopSub,所以我将这一行添加到我的代码中,它就像一个魅力:

EnableReadOnlyControls Me.frmCounterTopSub.Form

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-10-22
    • 1970-01-01
    • 2020-12-24
    • 2017-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多