I am using the following code as event handler for the button cmd_Edit on my main form:
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
The form loads with intCanEdit set to False. When i click the button once (setting it to true) everything works as expected, when i click it again (setting it to false again) i get an error (Runtime error 2455) with the Debugger sending me to the line i marked with asterisks in the above code.
Does anybody have an idea why i can set the property to True with my code, but get an error when i try to set the same property back to False? :(