Locking/Unlocking SubForm with Option Control

mjseim

Registered User.
Local time
Today, 12:26
Joined
Sep 21, 2005
Messages
62
Can someone help me fix this...

I'm just trying to create an Option Button that will Lock/Unlock a SubForm upon change. I've seen and read many other threads on this topic but still cannot get it to work. Other threads recommended adding/changing the tag on all the forms controls. I thought it would make more sense to simply edit the tag of the control making the changes. Here's what I have so far:

Code:
Private Sub ButtonLockForm_Click()

    If Me.ButtonLockForm.Tag = "Locked" Then
        For Each Control In Forms!Neighborhoods.HOA_Associations_subform.Form.Controls
            If Control.Name = "ButtonLockForm" Then
                Control.Locked = False
            Else
                Control.Locked = False
            End If
        Next Control
        Me.ButtonLockForm.Tag = "Unlocked"
    Else
        For Each Control In Forms!Neighborhoods.HOA_Associations_subform.Form.Controls
            If Control.Name = "ButtonLockForm" Then
                Control.Locked = False
            Else
                Control.Locked = True
            End If
        Next Control
        Me.ButtonLockForm.Tag = "Locked"
    End If

End Sub

Also, I know I will have to paste basically the same code in my FormOpen code but I kept having problems with that... ".Locked" wasn't a viable property of a control apparently.

Thanks.
 
Why are you using this:
Code:
If Control.Name = "ButtonLockForm" Then

You can only have one control named that anyway so you wouldn't need to loop. If you ARE needing to lock more than one control, then you should put something in each of the controls' tag property (like 'lock' without the quotes).

Then you would use:

Code:
If Control.Tag = "lock" Then

And make sure that you don't put the tag on a control that cannot be locked (for example a label).
 
You almost answered your own question. The reason I thought to use the ".name" property was to OMIT that control from being locked (as that is the control I intend to use as the option control for locking/unlocking the form). As you can see, the loop does loop through all controls in my form, it simply leaves the "ButtonLockForm" control unlocked in all cases (the If/Then statement is inside of my loop).

I would like to avoid tagging all of my controls as I may need to use the tags for other operations in the future.
 
Well you will need to then add in a check of the control types to lock. If you don't you will always get an error as you can't lock a label. I'm not sure, at the moment, which others you can't lock but you will need to add in:

If ctl.ControlType = acTextBox Then

Or

If ctl.ControlType <> acLabel Then

But I'm not sure for the second what will occur as there may be other controls you can't lock either.
 
Ahhh.... Gotcha! That makes sense why it isn't working. Alright, I suppose I'll just raise the white flag and submit to tagging my controls.

Wish me luck! And thank you very much for the insight.
 

Users who are viewing this thread

Back
Top Bottom