Make one of two check boxes required

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have two check boxes that are the foundation of two queries. Right now, I
user can fill out a form and "forget" to check one of the two boxes. I need
to have one of the two required before the user closes the form. I'm not
sure how to approach this.

Thanks
 
It sounds like you are saying that the user closes the form to save the
data. One approach might be to use the BeforeUpdate event of the form to
verify that one of two check boxes has been checked.

You'd create an event procedure for the BeforeUpdate event, and in it, you
could use something like:

If Me!chkFirstCheckBox + Me!chkSecondCheckBox = 0 Then
Cancel=True
End If

A value of "False" in a checkbox gets stored as a 0 (zero). Thus, if you
add the two checkboxes and get a 0, neither is checked.

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
Beyuduzz,

There are a couple of approaches you could take to this.

1. In design view of the table that the form is based on, select
Properties form the View menu. In the Validation Rule property, put the
equivalent of this...
[Your1stYesNoField]<>[Your2ndYesNoField]
Entere a suitable message for the Validation Text property.

2. On the Before Update event of the form, write code the equivalent of
this...
If Me.Your1stYesNoField = Me.Your2ndYesNoField Then
MsgBox "One of those checkboxes has to be ticked"
Cancel = True
End if
 
In the form's Before Update event you could have something like:

If Me.chkCheckBox1 = 0 and Me.chkCheckBox2 = 0 Then
MsgBox "You need to check at least one box"
Cancel = True
End If

0 in a Yes/No field is the equivalent of No (unchecked).

You may want to look into using an option group instead of 2 check boxes.
 
Beyuduzz,

I see that Jeff has assumed that both checkboxes ticked is valid,
whereas I assumed one or the other. Your call!
 
Steve,
No, your answer is more appropriate. The requirement is one of the two but
never both.

Thanks for the information.
--
I''m a novice with an advance way of thinking.


Steve Schapel said:
Beyuduzz,

I see that Jeff has assumed that both checkboxes ticked is valid,
whereas I assumed one or the other. Your call!

--
Steve Schapel, Microsoft Access MVP

Steve said:
Beyuduzz,

There are a couple of approaches you could take to this.

1. In design view of the table that the form is based on, select
Properties form the View menu. In the Validation Rule property, put the
equivalent of this...
[Your1stYesNoField]<>[Your2ndYesNoField]
Entere a suitable message for the Validation Text property.

2. On the Before Update event of the form, write code the equivalent of
this...
If Me.Your1stYesNoField = Me.Your2ndYesNoField Then
MsgBox "One of those checkboxes has to be ticked"
Cancel = True
End if
 
Thanks Bruce.
An option group is not an optino since too many queries as well as embedded
code rely on abs counts of the check boxes. Thanks, though, that actually
makes more sense after the fact.

Tom
 

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

Back
Top