Do Loop

  • Thread starter Thread starter B
  • Start date Start date
B

B

can anyone tell me why my loop is not working to click on all the check
boxes within my form

Dim check, counter, flag, st, vf
check = "chk": counter = 0: flag = 1: vf = ".Value": st = check & "" & flag
& "" & vf

Do While counter < 21
counter = counter + 1
If st = False Then
st = True
Else
st = False
flag = flag + 1
End If
Loop
 
I have ran the code myself and it runs fine. The value for the bollean is not true or false on the first run though, I think that is your error.It returns, 'chk1.value'.

Have you added watches on each of the values when you run the code? It is a great way to check your outputs a step at a time!
 
I am trying to get it to check the box.. I added the watches I guess I am
just missing something.. I wanted it to assign all checkboxes to checked
when ran
Andy Man via AccessMonster.com said:
I have ran the code myself and it runs fine. The value for the bollean is
not true or false on the first run though, I think that is your error.It
returns, 'chk1.value'.
Have you added watches on each of the values when you run the code? It is
a great way to check your outputs a step at a time!
 
B said:
can anyone tell me why my loop is not working to click on all the
check boxes within my form

Dim check, counter, flag, st, vf
check = "chk": counter = 0: flag = 1: vf = ".Value": st = check & ""
& flag & "" & vf

Do While counter < 21
counter = counter + 1
If st = False Then
st = True
Else
st = False
flag = flag + 1
End If
Loop

You are building this string initially in the variable st:
"chk1.Value". But the fact that it *looks* like a control reference,
it's still just a string. And then the first time through your loop you
are comparing that string to the boolean value False -- it won't be
equal, and then you are setting the variable st to False. Subsequent
iterations through the loop will just flip the value of the variable
from False to True, or from True to False. None of this will have any
effect on your check boxes at all.

I believe this is what you are trying to do:

Dim Counter As Integer

For Counter = 1 to 21
With Me.Controls("chk" & Counter)
.Value = Not .Value
End With
Next Counter

That's assuming you have 21 check boxes names "chk1" through "chk21".
 
Back
Top