ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Locking all text, combo and check boxes (https://www.excelbanter.com/excel-programming/441050-locking-all-text-combo-check-boxes.html)

Memphis[_2_]

Locking all text, combo and check boxes
 
Hello,
I have a user form with several text, combo and checkboxes, as well as
command buttons.
I would like for the user to check a check box and lock all txt,cmb and chk
boxes in the form once they are entering the data, but I want to keep the cmd
buttons enabled, so I do not need to lock the whole userform.

I would like to see if there is a way to do this in a "batch", for example
If chkbox1= True then "All txtboxes".Locked=True
I would hate to name every single one.

Thank you


B Lynn B

Locking all text, combo and check boxes
 
You can loop through the controls collection on your form. If you've
followed a good naming convention (i.e. command buttons are named something
like cmdName) then snippet below would work:

Sub LockControls()

Dim myCtrl as Control

For Each myCtrl in me.Controls
If Right(myCtrl.Name, 3) < "cmd" Then myCtrl.Locked = True
Next myCtrl

End Sub

"Memphis" wrote:

Hello,
I have a user form with several text, combo and checkboxes, as well as
command buttons.
I would like for the user to check a check box and lock all txt,cmb and chk
boxes in the form once they are entering the data, but I want to keep the cmd
buttons enabled, so I do not need to lock the whole userform.

I would like to see if there is a way to do this in a "batch", for example
If chkbox1= True then "All txtboxes".Locked=True
I would hate to name every single one.

Thank you


B Lynn B

Locking all text, combo and check boxes
 
Ahem. Uh, yes, that should have been the "other Right"...

If Left(myCtrl.Name, 3) < "cmd" Then myCtrl.Locked = True

"B Lynn B" wrote:

You can loop through the controls collection on your form. If you've
followed a good naming convention (i.e. command buttons are named something
like cmdName) then snippet below would work:

Sub LockControls()

Dim myCtrl as Control

For Each myCtrl in me.Controls
If Right(myCtrl.Name, 3) < "cmd" Then myCtrl.Locked = True
Next myCtrl

End Sub

"Memphis" wrote:

Hello,
I have a user form with several text, combo and checkboxes, as well as
command buttons.
I would like for the user to check a check box and lock all txt,cmb and chk
boxes in the form once they are entering the data, but I want to keep the cmd
buttons enabled, so I do not need to lock the whole userform.

I would like to see if there is a way to do this in a "batch", for example
If chkbox1= True then "All txtboxes".Locked=True
I would hate to name every single one.

Thank you



All times are GMT +1. The time now is 08:13 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com