nested variable

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have no idea what this is called but I want to set up a loop in VBA where
each pass changes the variable in an if statment.

Here is the situation. I have a form that has 50 + check boxes and I need to
count the total number of check boxes that have been clicked. Each Check box
has the same name except for number at the end. Q1, Q2, Q13, Q41, etc...

I thought there was a way to make an if statment that looked something like:

If Question(x) = "yes" then.....

the x would be part of the loop and would increase during each pass. So on
the first pass the if statment would look at the Question1 checkbox and then
on the 2nd pass it would look at Question2 and so on and so on.

Any Ideas would help.
 
If you mean something like that

Dim I as Integer, MySum as Integer
MySum = 0
For I=1 To 50
If Me("Question" & I) Then
MySum = MySum + 1
End If
Next I
' MySum will return the total of check
 
Dim q as Integer
Dim iCount as Integer

For q = 1 to 50
If Me.Controls("Q" & q) = True Then
iCount = iCount + 1
End If
Next q

HTH,
 
Back
Top