am trying to lock certain fields on a subform (resides on a main form) when it opens. I have tried to run the code using the On Load, On Open, On Current, (on both the main form and subform), however, it cannot and will not find the fields because the form isn't actually open yet. I have tried my code by using another change event on a form to ensure that it will lock the fields that need to be locked and it works. Does anyone have any idea on what event can I use to lock certain fields on the subform when opening the form? Thanking you in advance.
The Open, Load and Current events of a subform are raised before any of these events are raised for the parent form. The code to lock the controls should then be located on the Form_Open event handler of the subform:
Private Sub Form_Open(Cancel As Integer)
Dim ctl As Control
For Each ctl In Me.Controls
If ctl.ControlType = acTextbox Then ' lock all textbox controls.
ctl.Locked : True
What I do not understand though, is why you don't simply set the Locked property of these controls to True at Design time.