【发布时间】: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
【问题讨论】: