Check Box Name

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
 
K

Kevin Sprinkel

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
 
M

Mei Qin

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
.

.
 
K

Kevin Sprinkel

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
 

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