I needed to stop users from accidentally editing fields in several forms and subfoms. I'm not much of a programmer, so using code I found in various forums, I was able to turn off AllowEdits from On Current, then turn it back on when a button is clicked. Subforms are set to AllowEdits and AllowAdditions only when the parent form allows editing using On Enter.
However, if a subform doesn't have any records, I get Error 2474, "The expression you entered requires the control to be in the active window." The debugger stops on the following line: Screen.ActiveCo ntrol.Parent.Al lowAdditions = True
Here's the code I'm using:
What am I doing wrong and how can I work around it?
Thanks,
Frieda
However, if a subform doesn't have any records, I get Error 2474, "The expression you entered requires the control to be in the active window." The debugger stops on the following line: Screen.ActiveCo ntrol.Parent.Al lowAdditions = True
Here's the code I'm using:
Code:
'Called from clicking a button on the parent form
Public Function Edit()
Screen.ActiveForm.AllowEdits = Not Screen.ActiveForm.AllowEdits
End Function
'Called from On Current in the parent form
Public Function Read()
Screen.ActiveForm.AllowEdits = False
End Function
'Called from On Enter of the subform control
Public Function AddEditSub()
If Screen.ActiveForm.AllowEdits = True Then
Screen.ActiveControl.Parent.AllowAdditions = True
Screen.ActiveControl.Parent.AllowEdits = True
Exit Function
End If
End Function
'Called from On Enter of the subform control like previous when additions aren't needed
Public Function EditSub()
If Screen.ActiveForm.AllowEdits = True Then
Screen.ActiveControl.Parent.AllowEdits = True
Exit Function
End If
End Function
'Called from On Exit of the subform control
Public Function ReadSub()
Screen.ActiveControl.Parent.AllowAdditions = False
Screen.ActiveControl.Parent.AllowEdits = False
End Function
Thanks,
Frieda
Comment