For each loop - checkboxes

  • Thread starter Thread starter Hafeez Esmail
  • Start date Start date
H

Hafeez Esmail

How do I write a for loop out of the following pseudocode?

For Each checkbox in this form
If checkbox.Value = True Then
*do something (nothing fancy)*
End If
Next checkbox

I want to cycle through each checkbox to see if it has
been checked. I know I could use a tonne of "If...Else"
statements but I'd rather try something more efficient.

Any help would be muchly appreciated!
Hafeez Esmail
 
Hafeez,
Something like the following should work

dim ctl as control
For Each ctl in me.Controls
With ctl
Select Case .ControlType
Case acCheckBox
if .value=true then
*do something (nothing fancy)*
endif
End Select
End With
Next ctl

HTH,
John
 
-----Original Message-----
How do I write a for loop out of the following pseudocode?

For Each checkbox in this form
If checkbox.Value = True Then
*do something (nothing fancy)*
End If
Next checkbox

I want to cycle through each checkbox to see if it has
been checked. I know I could use a tonne of "If...Else"
statements but I'd rather try something more efficient.

Any help would be muchly appreciated!
Hafeez Esmail
.
Hi Hafeez,

dim ctl as control

for each ctl in controls
if ctl.controltype=accheckbox then
msg ctl.checked
end if
next ctl

Luck
Jonathan
 
Hi John,
Thanks for your help for giving me the structure of this
for loop. I would have never found out how to structure
this because some of the properties don't show up in the
list box when you press the "."!

I have two symptoms which may be stemming from one problem.

The first question is how do you add two strings together?
My current method is as follows:
strSQL = "SELECT * FROM tblOne"

if strSQL <> "*WHERE*" Then
strSQL = strSQL & "WHERE ((tblOne!Colour = "Red")"
else
strSQL = strSQL & "AND (tblOne!Colour = "Red")"
end if

Right now, no matter what order i click the boxes, it will
always retrieve the last box on the list (or whichever is
closest) and return "WHERE ((tblOne!Colour = "****")" (***
indcating the name of box I clicked.
Which leads to my section question. How come it always
selects the check box that's closest to the one at the end
of the list, instead of selecting all of the boxes that
are checked?

I know it's wordy, but I would appreciate any help you can
offer. Thanks
Hafeez Esmail
 
I took one more crack at it and I finally debugged the
probelm!

Thanks for all your help!!
Hafeez Esmail
 
Back
Top