【问题标题】:MS Access: Setting the .enabled and .allowedits property of a subform through VBAMS Access:通过 VBA 设置子窗体的 .enabled 和 .allowedits 属性
【发布时间】:2017-03-23 21:59:37
【问题描述】:

我希望创建一个 VBA 子过程来更改多个主窗体的所有子窗体的 .enabled.allowedit 属性。这个想法是我有一个子过程,可以通过我的应用程序中任何表单上的按钮调用。

单击按钮会设置我用来引用按钮所在主窗体的变量。我目前将它用于 .enable 部分,但是我一直收到有关 .allowedits 属性的错误。下面是我使用的代码。我得到的错误是

对象不支持该属性或方法

它只发生在.allowedits 行运行之后。任何帮助将不胜感激。谢谢!

cmdbutton_on_click_event

Private Sub cmdEditAll_Click()
strFormName = Me.Name

Call ToggleEdit

end sub

调用的子过程:

Option Compare Database
Public strFormName As String
Sub ToggleEdit()
Dim ctrlControl As Control


On Error GoTo err:
For Each ctrlControl In Forms(strFormName).Controls
    Debug.Print ctrlControl.Name
    If booEnabled = False Then
        Forms!frmfullcourseinfo.cmdEditAll.Caption = "Edit"
        Forms!frmfullcourseinfo.lblMode.Caption = "[Read Only]"
        If ctrlControl.ControlType = acTabCtl Or ctrlControl.Name = "Command9" Or ctrlControl.Name = "cmdeditall" Then
        Else
        ctrlControl.Enabled = False
        ctrlControl.AllowEdits = False
        End If

    Else
        Forms!frmfullcourseinfo.cmdEditAll.Caption = "Stop Edit"
        Forms!frmfullcourseinfo.lblMode.Caption = "[Edit Mode]"
        If ctrlControl.ControlType = acTabCtl Or ctrlControl.Name = "Command9" Or ctrlControl.Name = "cmdeditall" Then
        Else
        ctrlControl.Enabled = True
        ctrlControl.AllowEdits = True
        End If
    End If
Continue:
Next

booEnabled = Not (booEnabled)
Exit Sub
err:
    Debug.Print err.Description
    Resume Continue
End Sub

【问题讨论】:

    标签: ms-access vba


    【解决方案1】:

    我总是给子表单容器控件一个与其持有的对象不同的名称,例如 ctrOrders。子表单容器控件没有 AllowEdits 属性,表单有,因此必须引用容器保存的表单对象。

    Me.ctrOrders.Form.AllowEdits = False

    所以这可能有效:

    ctrlControl.Form.AllowEdits = False

    【讨论】:

    • 谢谢,等我早上回到办公室再试试看!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-10-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-05
    • 1970-01-01
    • 2017-02-23
    相关资源
    最近更新 更多