Form Required Field Question

  • Thread starter Thread starter josh
  • Start date Start date
J

josh

I have a form that gives the user the option of selecting
a department from 2 different check box options. I was
wondering if there is any way to require that the user
check at least 1 of the boxes. I know how to require 1
field to be filled in, but I'm not sure how to require
that either "Field1" or "Field2" is filled in. Thanks
 
josh said:
I have a form that gives the user the option of selecting
a department from 2 different check box options. I was
wondering if there is any way to require that the user
check at least 1 of the boxes. I know how to require 1
field to be filled in, but I'm not sure how to require
that either "Field1" or "Field2" is filled in. Thanks

This should be one field controlled with an option group. You store a 1 to represent
one department and a 2 to represent the other. Then you make that one field a
required field as normal.
 
If this is an option group the selection is mutually exclusive so only 1
dept can be used. Josh has said he is using check boxes which according to
Windows design rules would allow more than 1 department.
Josh, go with Rick's comments if only 1 department can be selected,
otherwise you need to write some code on the before update event.

If ChkDept1.Value or chkDept2.Value then
'We are ok
Else
'Do your screen / user prompts here
End if
 
There were some Access bugs (in A2K, I think) associated with CheckBox
values used in Boolean expressions for If statement this way. To avoid the
bug from occurring, use explicit comparison like:

If (ChkDept1.Value = True) OR (chkDept2.Value = True) Then
....
 
JohnFol said:
If this is an option group the selection is mutually exclusive so only 1
dept can be used. Josh has said he is using check boxes which according to
Windows design rules would allow more than 1 department.
Josh, go with Rick's comments if only 1 department can be selected,
otherwise you need to write some code on the before update event.

If ChkDept1.Value or chkDept2.Value then
'We are ok
Else
'Do your screen / user prompts here
End if

You're right. I didn't consider that checking both departments might be required. I
would then use John's method. If you really wanted it enforced at the table level I
suppose an option group with a third value for "Both Departments" could be used.
Otherwise a Table-Level validation rule might be possible. I'm not sure because
validation rules at the table level are more restrictive in what you can do than they
are at the form level and I haven't used them much.
 
Back
Top