View Full Version : Alternative to If statement


Blkblts
03-09-2001, 12:55 PM
I have a form that has several check boxes. I need to know if cb5, cb7, cb12, cb19, cb24, cb25 cb30 and so on have been checked. I also need to know if the count of these checkboxes that have been checked is greater then say 4.

I can write the statements individually such as If [cb5] = -1 then
Count = count + 1
End If
IF blah blah.....

What I would like to know. Is there a more efficient way? Because my checkbox are not in order and skip certain fields in between I can not come up with a viable solution.

I appreciate your expertise....

Thanks
kim

llkhoutx
03-09-2001, 01:10 PM
Loop through the controls on your form if its a checkbox (check the control type) increment your counter:

dim ctl as control
dim icnt as integer
icnt = 0
For each ctl in Me
if ctl.controlType = acCheckBox then
icnt = icnt + 1
end if
next

this assumes that you'll be checking all checkboxes on your form. Jump out if ctl.Name is a checkbox you don't want to count

Blkblts
03-09-2001, 01:16 PM
That's the thing I only randomly need about 20 out of 60 checkboxes. like 5,11,26,27,28,31,32,33,39,41,42,43,44,46,47,58 etc. So I don't think that will work.

Tks
Kim

Fornatian
03-09-2001, 11:05 PM
If you only need to check certain checkboxes then enter a "Y" in the tag property of the checkboxes and use the same code as above but this time check for presence of the "Y" like this:

dim ctl as control
dim icnt as integer
icnt = 0
For each ctl in Me
if ctl.controlType = acCheckBox then
if ctl.tag = "Y" then
if ctl.value = true then
icnt = icnt + 1
end if
end if
end if
next

Syntax maynot be entirely correct but you get the idea of using the tag property to identify only certain checkboxes.

Ian

Blkblts
03-12-2001, 05:45 AM
Wonderful, Kudos to you.

kim