Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2005
    Posts
    79

    Unanswered: Lock subform controls upon loading

    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.

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    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:
    Code:
    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
            End If
        Next ctl
    
    End Sub
    What I do not understand though, is why you don't simply set the Locked property of these controls to True at Design time.
    Have a nice day!

  3. #3
    Join Date
    Nov 2005
    Posts
    79

    Smile Thank You

    I ended up utilizing the code of locking the entire form/subform upon loading and then I utilized a case statement of locking the few controls that need to be unlocked.

    I will try working on using the Subform's Open_Event and pray

    Thank you.

  4. #4
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    You're welcome!
    Have a nice day!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •