limiting checkbox choices

E

Eric

Hi,
I have a form with 6 checkboxes for different sandwiches that our personall
can order.
However they can order 2 different sandwiches at the most at one day.
How can i make sure that from the 6 checkboxes max two are checked at the
same time?
 
S

S.Y.M. Wong-A-Ton

You need a way to detect how many checkboxes have been selected. One way to
do this is by placing the check box in a repeating table and then pre-filling
the repeating table (see
http://www.bizsupportonline.net/infopath2007/how-to-prefill-infopath-repeating-table.htm)
with 6 rows to get your 6 check boxes. Then you can disable adding and
removing of rows of the repeating table via its Properties dialog box.

Now you can count the amount of check boxes that have been selected, by
using the count() function on the field for the check box and filter on the
value of "true" or "1" to find only those check boxes that have been
selected. But to perform the count over the repeating table, you have to use
a helperField as described in
http://www.bizsupportonline.net/infopath2003/avg-function-infopath.htm, but
then using the count() function. A rule on the check box in the repeating
table would set the helperField value to an empty string and then to any
piece of text. And a rule on the helperField would set the value of another
field to the count over the check boxes in the repeating table. You can make
both the helperField and count field hidden fields (see
http://www.bizsupportonline.net/blog/2008/11/how-to-create-a-hidden-field-in-infopath/).

Alternatively, if you don't want to add the check boxes to a repeating table
or use the method described above, you can add 2 rules to each check box. The
first rule would have a condition on it to run only when the check box is
checked and then set the value of a count field to the current value of the
count field + 1. The second rule would have a condition on it to run only
when the check box is unchecked and then set the value of a count field to
the current value of the count field - 1. This way you can get a running
total of how many check boxes have been checked. You can make the count field
hidden.

Once you've got a field that counts how many check boxes have been selected,
you can do one of 2 things:
1. Use data validation on the check boxes to display an error if the count
is greater than 2.
OR
2. Use conditional formatting on the check boxes to disable all check boxes
as soon as 2 check boxes have been selected, so if the count is equal to 2.
You would have to add an extra button to clear the selections, should the
user want to start all over again.

Hope this helps.
 

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