Check Box Name

  • Thread starter Thread starter Mei Qin
  • Start date Start date
M

Mei Qin

Hello,

I have a group of check box name chk1-9. In my code I want
to loop say for i = 1 to 9 chki.value = true. What is the
right way to pass i? I tried different ways, but got error
with chk

Thank for any help!

Mei
 
Hi, Mei.

You have to turn the index into a string first. Something
like:

strCBName = "chk"
For i = 1 to 9
strCBName = strCBName & Str(i)
' Do your stuff here
Next i
 
I did. Then when I say strCBName.value = false. It gave me
error. I tried to DIM strCBName as string or Variant.
-----Original Message-----
Hi, Mei.

You have to turn the index into a string first. Something
like:

strCBName = "chk"
For i = 1 to 9
strCBName = strCBName & Str(i)
' Do your stuff here
Next i
-----Original Message-----
Hello,

I have a group of check box name chk1-9. In my code I want
to loop say for i = 1 to 9 chki.value = true. What is the
right way to pass i? I tried different ways, but got error
with chk

Thank for any help!

Mei
.

.
 
My apologies, Mei.

You must use a Control object and point it to each name.
The following code sets checkboxes Check1, Check2, Check3,
and Check4 to True. You could also loop through the
entire collection if you wanted to do something for each
checkbox, rather than this particular series. See VBA
Help on the Control object.

Private Sub cmdSetAllToTrue_Click()
Dim ctl As Control
Dim strCBName As String
strCBName = "Check"
For I = 1 To 4
Set ctl = Me.Controls(strCBName & LTrim(str(I)))
ctl.Value = True
Next I
End Sub

HTH
Kevin Sprinkel
 
Back
Top