Checkboxes

G

Guest

I have a worksheet that has 5 checkboxes. I used the Contol Toolbox to place
these in the worksheet. How can I make sure the user checks at least one of
the 5 checkboxes? I would like to add the code to a command button that the
user will click when they send the form.
 
B

Bob Phillips

Put this code behind the commandbutton

Private Sub CommandButton1_Click()
If Not Me.CheckBox1.Value And _
Not Me.CheckBox2.Value And _
Not Me.CheckBox3.Value And _
Not Me.CheckBox4.Value And _
Not Me.CheckBox5.Value Then
MsgBox "Nothing selected, try again"
Else
'do your stuff
End If
End Sub

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 
S

Susan

(think Horseshack from Welcome Back Kotter)
ooooh! ooooh! i know that one!!!!
:) [with the disclaimer that SOMEBODY probably
knows a better way to do it!]

sub checks() 'untested

If chk1.Value = False And _
chk2.Value = False And _
chk3.Value = False And _
chk4.Value = False And _
chk5.Value = False Then

Msgbox "You must check at least one checkbox!", vbExclamation +
vbOkOnly

Else

'enter code to do if not ALL are unchecked.

End If
End sub

susan
 
G

Guest

You Guys are the best.

Thanks Bob & Susan

TH



Bob Phillips said:
Put this code behind the commandbutton

Private Sub CommandButton1_Click()
If Not Me.CheckBox1.Value And _
Not Me.CheckBox2.Value And _
Not Me.CheckBox3.Value And _
Not Me.CheckBox4.Value And _
Not Me.CheckBox5.Value Then
MsgBox "Nothing selected, try again"
Else
'do your stuff
End If
End Sub

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 

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

Top