Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Quick Syntax Question 1

Status
Not open for further replies.

JasonPurdueEE

Technical User
May 21, 2002
131
US
Hello everybody.
I have 41 check boxes (named chk1, chk2, chk3...chk41). I'm trying to use a do while loop to go through them all. I have the counter count up from 1 to 41 and I want to append the counter number to the end of the "Me.chk" part. Whats the correct syntax for the Me.chk&Counter part? Thank you.

****************************
Counter = 0
Do While Counter <= 41
Counter = Counter + 1
If Not Me.chk&Counter <> -1 Then
do something here
End If
Exit Do
****************************
JASON

______________________________
Sleep is a poor substitute for coffee.
 

What application is this for? Excel? Access?

If it is for Excel, the easiest way to accomplish your task is to assign a cell to the ControlSource property of each check box and then process the range of assigned cells. For example, assign AX1 to the first check box, AX2 to the second, and so on thru AX41. Then process the range AX1:AX41 to see the current values. Hide the column if you wish.

 
Access 2K

______________________________
Sleep is a poor substitute for coffee.
 
To clarify: I need the if statement in the loop to end up evaluating Me.chk1, Me.chk2....Me.chk41

the line of code I need help with is:
If Not Me.chk&Counter <> -1 Then

as it is, this doesnt run. what would be the proper syntax for the bolded part? Thanks.

______________________________
Sleep is a poor substitute for coffee.
 
Try something like this (It works in Access 97, I don't have 2K here, but it should work in 2K as well.):
[blue]
Code:
Private Sub Command1_Click()
Dim i As Integer
  For i = 1 To 4
[green]
Code:
  ' <-- change for actual number of check boxes
[/color]
Code:
    MsgBox Controls(&quot;chk&quot; & i)
  Next i
End Sub
[/color]

 
Thank you for your help Zathras! Here's what I ended up with:


For i = 1 To 41
If Not Controls(&quot;chk&quot; & i) <> -1 Then
MsgBox (&quot;chk&quot; & i) & &quot; is checked&quot;
End If
Next i

______________________________
Sleep is a poor substitute for coffee.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top