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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

One or more boxes checked

Status
Not open for further replies.

ZoomerZ

MIS
Jul 15, 2004
230
US
Hi!
I have 15 check boxes. I need to write a code
If 1 checked - do this
If more then one checked - do something else

Please, help
 
So I understand I have to count boxes and use Array?
Or there is another way?
It does not matter which box checked - just one or more then one...Thanks
 
Well... I'm a newbie. So the way I would write it, it would be al lot of work. Perhaps there is another way. At least I'm trying.. ;)

Code:
If Check1.Checked = True then
   'do this
ElseIf Check1.Checked And Check2.Checked = True Then
   'do something else
End if

---------------------------------------
This will be the day when all of God’s children will be able to sing with a new meaning, “My country, ‘tis of thee, sweet land of liberty, of thee I sing. Land where my fathers died, land of the pilgrim’s pride, from every mountainside, let freedom ring. - Marten Luther King
 
Hi ZoomerZ

Assuming that you have all 15 Checkboxes in a control array this would work.

Code:
Private Sub Command1_Click()
Dim i As Integer
Dim n As Integer

n = 0

For i = 1 To 15
    If Check1(i).Value = "1" Then n = n + 1
Next

Select Case n
Case "1"
MsgBox "One"
Case Is > "1"
MsgBox "More than one"
Case Else
MsgBox "None"
End Select
End Sub

Hope this helps

Harleyquinn
 
Loop through the control collection, see if it's a checkbox and if so increment a counter for each checked value. At then end of the loop the counter will show number of checked boxes

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'

for steam enthusiasts
 
Or you could maintain a form level counter and increment/decrement in the click event of the checkbox.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top