Field Required if other field = A

C

consjoe

In my form I have a drop down box with three Options A,H,L
If A is selected then another field (Due Date) needs to be required.
If H or L is selected then field (Type) needs to be required.
However, if A is selected there will never be a Type and if H or L is
selected there will never be a due date.
Thanks for your help in advance.
I couldn't get this to work but the best I came up with was this:

If (Me.Option) = "A" Then
Require (Me.Due_Date)
If IsNull(Me.Due_Date) then
Msgbox "All A's must have a due date"
else
Goto AddingRecord
endif
endif
If (Me.Option) = "H" or If (Me.Option) = "L"
Require (Me.Type)
If IsNUll(Me.Type) then
Msgbox "All H's and L's must have a type"
else
Goto AddingRecord
endif
endif

AddingRecord:
 
6

'69 Camaro

You're welcome. As I mentioned in my earlier post, the code was an example,
but you need to change the control names to match your own.

And if Me.Option = "A" works in your code, then your combo box was probably
set up using the Wizard with values typed into a single column (which are
stored as values in the control, not as records in a table). Even though
the Wizard allows this, it's a non-standard practice because it isn't very
flexible or expandable (which usually requires a complete rework). However,
if you know you will never modify this combo box, then you already have what
suits your needs and shouldn't mess with it.

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address so that a message will
be forwarded to me.)
 
6

'69 Camaro

Whoa! One should never blindly copy code. If you do not know where to put
this code, then you intend to do just that. Blindly copying code can have
disasterous consequences that may take a great deal of time and effort to
locate the trouble and fix it. I suggest that you get some training, or
study some books on Access, or study Access Help, or study Microsoft's
Knowledge Base, or preferably a combination of all of these to learn about
what does what and what goes where.

When you have questions, post them from the following Web page for Access
beginners:

http://www.microsoft.com/communitie...988-3566-454b-86f8-58c07ed6b1d7&lang=en&cr=US

The answers one receives there are geared for beginners, not advanced and
expert users as this newsgroup is intended for.

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address so that a message will
be forwarded to me.)
 
M

Michel Walsh

Hi



Another possibility is to define the "rule" at the table design. You can
add a table validation rule (really, it is a record validation, in scope)
such as:


( (field1 ="A") IMP (Not (field2 IS NULL)) )
AND
( (field1 IN("L", "H")) IMP (Not (field3 IS NULL)) )



The logical operator IMP (imply) having the following truth table:


x IMP y y:true y:false y:null
x:true true false null
x:false true true true
x:null true null null



As written, if field1 <> "A", then field2 can have a value, or not.



Hoping it may help,
Vanderghast, Access MVP
 
Top