Userform Controls

G

Guest

I have a userform with 26 Labels, 13 TextBoxes and 2 CommandButtons. What I
want to know is if there is a loop code to loop through each control
regaurdless of it's type and set Enable to False according to the Controls
name? I have the Labels and TextBoxes named Cntrl1 thru Cntrl39.
Thanks
 
R

Randy

I'm not sure of exactly which controls you want to disable, so you
will have to adjust the logical test in the If statement, but this
should give you the idea (paste this code within the click event of a
button or trigger it as you want):

Private Sub CommandButton1_Click()
Dim c As Control
For Each c In Me.Controls
If c.Name = "Cntrl1" Then
c.Enabled = False
End If
Next
End Sub

Good luck,
Randy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top