Collections

  • Thread starter Thread starter sunhealth
  • Start date Start date
S

sunhealth

Hi,
I have a series of 15 checkboxes on a form and I would like to use a
collection to loop through
them to see if one or more have been checked. Using an if statement is
so cumbersome with so many boxes. Any thoughts would be appreciated.
Thanks to all
Sun Health
 
Sum the checkboxes.
IIF(Int([CK1]+[CK2]+....+[CK15])>0, "Something is checked","None checked")
 
Summing the check boxes is one option, but the False value is zero and the
True value is -1, so it won't be >0. Also, you'll need to make sure that you
have a default value set so that they can't be Null.

There are a few ways to loop through controls.

1) Give them a name that ends with consecutive numbers.

Example:
Dim i As Integer
For i = 1 To 15
If Me.Controls("chkMyCheckbox" & i) = True Then
'do whatever here
End If
Next i

2) Loop through all controls and check for checkbox controls.

Example:
Dim ctl As Control
For Each ctl In Me.Controls
If ctl.ControlType = acCheckbox Then
'do whatever here
End If
Next

3) Set the Tag property of the checkboxes you want to inspect and loop
through all controls as in #2, but check the Tag property instead of the
ControlType.

--
Wayne Morgan
MS Access MVP


KARL DEWEY said:
Sum the checkboxes.
IIF(Int([CK1]+[CK2]+....+[CK15])>0, "Something is checked","None checked")

sunhealth said:
Hi,
I have a series of 15 checkboxes on a form and I would like to use a
collection to loop through
them to see if one or more have been checked. Using an if statement is
so cumbersome with so many boxes. Any thoughts would be appreciated.
Thanks to all
Sun Health
 
Name your checkboxes CheckBox1, CheckBox2, CheckBox3,.......CheckBox15

Use the following code to check each checkbox to see if it is checked:
Dim I as Integer
Dim NumCheckBoxesChecked As Integer
NumCheckBoxesChecked = 0
For I = 1 to 15
If Me("CheckBox" & I) = True Then
NumCheckBoxesChecked = NumCheckBoxesChecked + 1
End If
Next I
MsgBox "The Number Of CheckBoxes Checked = " & NumCheckBoxesChecked
 
"PC D" <[email protected]> schreef in bericht
--
PC Datasheet
Your Resource For Help With Access, Excel And Word Applications 'Resource ????
Over 1175 users have come to me from the newsgroups requesting help '1175 users ????
(e-mail address removed)

--
To Steve:
Why PC D ? Why not PCD anymore, or Access Resource or Help available or why not just PC DataSheet?
You think that changing names is vital for you? It seems like a second nature but ...
No-one wants your advertising/job hunting here!
Over 700 !! users from the newsgroups have visited the website to read what kind of a 'resource' you are... (rapidly increasing..)

To the original poster:
Most people here have a common belief that the newsgroups are for *free exchange of information*.
But Steve is a notorious job hunter in these groups, always trying to sell his services.

Before you intend to do business with him look at:
http://home.tiscali.nl/arracom/whoissteve.html

Arno R
 

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

Back
Top