我使用以下代码作为主窗体上cmd_Edit按钮的事件处理程序:
Private Sub cmd_Edit_Click()
If intCanEdit = False Then
If MsgBox("Sollen vorhandene Prozeduren verändert werden ?", vbYesNo, "Frage") = vbNo Then Exit Sub
Me.AllowEdits = True
Me.AllowAdditions = True
Dim sbfrm As Control
For Each sbfrm In Me.Controls
With sbfrm
Select Case .ControlType
Case acSubform
.Form.AllowEdits = True
.Form.AllowAdditions = True
End Select
End With
Next sbfrm
intCanEdit = True
Else
Me.AllowEdits = False
Me.AllowAdditions = False
For Each sbfrm In Me.Controls
With sbfrm
Select Case .ControlType
Case acSubform
**.Form.AllowEdits = False**
.Form.AllowAdditions = False
End Select
End With
Next sbfrm
intCanEdit = False
End If
cmd_Edit.Caption = IIf(intCanEdit, "Click to Save", "Click to Edit")
cmd_Edit.BackColor = IIf(intCanEdit, vbRed, vbGreen)
End Sub
表单加载时intCanEdit设置为False。当我单击按钮一次(将其设置为true)时,一切都按预期工作,当我再次单击它时(再次将其设置为false)我收到错误(运行时错误2455),调试器将我发送到标有星号的行在上面的代码中。
有没有人知道为什么我可以用我的代码将属性设置为True,但是当我尝试将相同的属性设置回False时会出错? :(