Multiple ComboBoxes but one must be Checked

F

Flydianslip

I have 22 CheckBoxes and I want to make sure one of them is required to be
Checked. If not I want a MsgBox to come up.

I'm testing it now, on just one CheckBox but I can't even get this to work.

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.Check216 = "No" Then
MsgBox "Please fill in the Job Type"
Cancel = True
End If
End Sub

Any help would be appreciated. Thank you.
 
S

Stuart McCall

Flydianslip said:
I have 22 CheckBoxes and I want to make sure one of them is required to be
Checked. If not I want a MsgBox to come up.

I'm testing it now, on just one CheckBox but I can't even get this to
work.

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.Check216 = "No" Then
MsgBox "Please fill in the Job Type"
Cancel = True
End If
End Sub

Any help would be appreciated. Thank you.

The value of a checkbox is of boolean data type (True or False), so your
code should be:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.Check216 = False Then
MsgBox "Please fill in the Job Type"
Cancel = True
End If
End Sub

(Get into the habit of using indentation - you'll thank yourself further
down the road)
 
M

Maurice

Try:

If Me.Check216 = false Then
....

and see if that gives you the desired output.
 
J

John W. Vinson

I have 22 CheckBoxes and I want to make sure one of them is required to be
Checked. If not I want a MsgBox to come up.

If these are bound to 22 fields in a table... your table design is almost
certainly WRONG. Could you consider instead a *single* numeric field with
values 1 to 22 (or maybe to 25 when you someday add three new options)?

Then you could use an Option Group control with 22 radio buttons or
checkboxes; the Option Group control would have just one value and allow only
one box to be checked.
I'm testing it now, on just one CheckBox but I can't even get this to work.

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.Check216 = "No" Then

This is failing because you're comparing the checkbox control (which can take
on values 0 for False, -1 for True) with a text string "No". This comparison
will never be true. You could replace "No" with a zero (no quotes), but you'ld
need 22 ugly If blocks... you should really reconsider the table design!
 
J

John Spencer

***IF*** you have 22 checkboxes and one or more must be checked, you can use

IF Me.Check216 Or Me.Check217 or Me.CheckAA Or Me.CheckN Or ... THEN
'One or more is checked so do nothing
ELSE
MsgBox "Please check something"
Cancel = True

END IF

This sounds as if you have a mis-designed data structure. See some of the
other posts in this thread.

John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County
 

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