Reducing the number of lines of code required

  • Thread starter Thread starter Alan T
  • Start date Start date
A

Alan T

I'm trying to create a form for work and I have the following lines o
code created within it... I have another 20 checkboxes which wil
require similar lines of code. Is there any way to cut down on th
total number of lines required (as it will end up being a ridiculou
size otherwise)?

CheckBox5.Value = False
TextBox14.Enabled = False
TextBox14.BackColor = RGB(128, 128, 128)
CheckBox6.Value = False
TextBox15.Enabled = False
TextBox15.BackColor = RGB(128, 128, 128)
CheckBox7.Value = False
TextBox16.Enabled = False
TextBox16.BackColor = RGB(128, 128, 128)
CheckBox8.Value = False
TextBox17.Enabled = False
TextBox17.BackColor = RGB(128, 128, 128)

Thank
 
If the controls are consecutively numbered you can do something like:

Private Sub CommandButton1_Click()
Dim Counter As Integer
For Counter = 1 To 20
Controls("CheckBox" & Counter).Value = False
Next
End Sub

You can rename the controls if need be to fit with this scheme.
 
Back
Top