Conditionally required field

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

Guest

On my form, I want to require the user to give additional information if they
check a box labeled NO. The additional information consists of 6 check boxes
and at least one must be selected. I would also like a pop-up message to
appear informing the user what to do and to not allow the user to save the
record unless the required information is entered.
 
Use the form's Before Update event to check for the desired conditions and
cancel the update if necessary.

Private Sub Form_BeforeUpdate(Cancel As Integer)

With Me
If .chkNo then
If .chk1 + .chk +.chk3 + .chk4 +.chk5 +.chk6 = 0 Then
Msg Box "At Least One Must be Selected"
Cancel = True
End If
End If
End With
End Sub
 
Kim and I are working on this issue and we were wondering if there should be
some sort of "condition" on the 'If .ckNo Then' statement? Should there be
'= true'?
 
It would be okay, but is not required. Any Boolean(yes/no, True/False,
On/Off) value can be tested on its own. Since a check box has only 2
possible values (True = -1, False = 0), it will return either True or False.
The only exception is if TripleState has been set to yes, it can be null.

Taking the concept even a bit further, here is a techniqu I use to create a
loop where multiple conditions may end the loop:

Do While True
'Some Code.....
If Condition met Then
Exit Do
End If
Loop

So, True is always True (There is no relativism in computers) It will stay
in the loop until you jump out.

Are you having trouble?
 
No, we haven't tried the code yet, but the question came up in looking at the
code. We'll let you know if there is a problem. Thanks alot!
 
Back
Top