coding possibility?

S

scott04

I have several yes/no boxes that i am trying to code but am running into
problems.
The main yes/no box is named system_issue and have 4 yes/no linked to that
lets name them box1, box2, box3, and box4 just to make it easier. I already
have it coded so that if the box is selected as No then all the 4 boxes
automatically set to no. See below:
Private Sub System_issue_AfterUpdate()
If Me.Systemissue = False Then
Me.box1 = False
Me.box2 = False
Me.box3 = False
Me.box4 = False
End If
My question is how do i code it so that if the answer is yes it requires
that at least one or more of the 4 boxes contain a yes? Any thoughts or
suggestions?
 
D

Douglas J. Steele

What you can do is take advantage of the fact that a checked check box has a
value of -1, while an unchecked one has a value of 0. That means you can
check:

If (Abs(Nz(Me.box1, 0)) + Abs(Nz(Me.box2, 0)) + Abs(Nz(Me.box3, 0)) +
Abs(Nz(Me.box4, 0))) = 0 Then
MsgBox "You must check at least one of the check boxes."
End If

The only reason for the Nz functions there is to handle the case where the
check box isn't initialized (when it's grayed out). If you're positive that
that will never be the case, you can get away with


If (Abs(Me.box1) + Abs(Me.box2) + Abs(Me.box3) + Abs(Me.box4)) = 0 Then
MsgBox "You must check at least one of the check boxes."
End If
 
F

fredg

I have several yes/no boxes that i am trying to code but am running into
problems.
The main yes/no box is named system_issue and have 4 yes/no linked to that
lets name them box1, box2, box3, and box4 just to make it easier. I already
have it coded so that if the box is selected as No then all the 4 boxes
automatically set to no. See below:
Private Sub System_issue_AfterUpdate()
If Me.Systemissue = False Then
Me.box1 = False
Me.box2 = False
Me.box3 = False
Me.box4 = False
End If
My question is how do i code it so that if the answer is yes it requires
that at least one or more of the 4 boxes contain a yes? Any thoughts or
suggestions?

Code the Form's BeforeUpdate event:

If Nz([Box1],0) + Nz([Box2],0) + Nz([Box3],0) + Nz([Box4],0) = 0 then
MsgBox "At least one of the check boxes must be checked."
Cancel = True
End If
 

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