User Forms - loop through controls to lock/unlock

CarolynS

Board Regular
Joined
Oct 27, 2015
Messages
56
HI

I am trying to loop through some (not all) boxes on a user form to lock/unlock them when a particular command button is clicked. The controls in questions all have names that start with "POinv" and then a number. I have the following code but it's not working as it doesn't seem to like controls.locked. How else can I do this?

Private Sub CommandButton2_Click()
'validate purchase order info on invoice form
Dim x As Integer
'unlock text boxes
For x = 1 To 11
Me.Controls("POinv" & x).Locked = False

Next


End Sub

Thanks in advance
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
What type of controls are they?
 
Upvote 0
text boxes and combo boxes but thinking about it I don't actually need the combo boxes. I could change them to text boxes
 
Upvote 0
I should probably also have mentioned that each box is numbered 1 - 11 hence why I'm using for x = 1 to 11. This has worked fine in other pieces of code I've used with this user form but it doesn't seem to like .locked
 
Upvote 0
I created a temp form with the stated controls named as listed and your code ran fine for me. It really shouldn't matter, but you might try:

<font face=Courier New>Me.Controls(CStr("POinv" & x)).Locked = <SPAN style="color:#00007F">False</SPAN></FONT>

You may wish to confirm the names. Typos kill us all.

BTW, what type error and if you put a breakpoint on Private Sub CommandButton2_Click(), and step thru it, what line errors?

Mark
 
Upvote 0
Are there any labels among the group of controls you are trying to lock/unlock?
 
Upvote 0
I created a temp form with the stated controls named as listed and your code ran fine for me. It really shouldn't matter, but you might try:

<font face=Courier New>Me.Controls(CStr("POinv" & x)).Locked = <SPAN style="color:#00007F">False</SPAN></FONT>

You may wish to confirm the names. Typos kill us all.

BTW, what type error and if you put a breakpoint on Private Sub CommandButton2_Click(), and step thru it, what line errors?

Mark

Thanks Mark. I'm out at the moment but will get the error type later
 
Upvote 0

Forum statistics

Threads
1,215,111
Messages
6,123,159
Members
449,098
Latest member
Doanvanhieu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top