Conditional Formating - Validation

J

JB

I have 2 fields on the form. If one is filled in, the other one needs to be
as well.
However, they both can be blank.

Any ideas?
 
K

Klatuu

You can use the Before Update event of the form to check for this condition:
Warning! Untested Air Code

If (IsNull(Me.TextBox1) And Not IsNull(Me.TextBox2)) Or _
(Not (IsNull(Me.TextBox1) And IsNull(Me.TextBox2))) Then
Then MsgBox "Both Text Boxes Must Be Filled In"
Cancel = True
End If
 
D

David C. Holley

Let me introduce you to the wonders of a truth table

Length Length
Field1 Field2 Result Action
0 0 VALID No Information Present
0 1 VALID Information missing
1 0 VALID Information missing
1 1 VALID Information present

From there just build your If...Thens as in

If Len(Field1) = 0 AND Len(Field2) = 0 Then

If (Len(Field1) = 0 AND Len(Field2) > 0) OR (Len(Field1) > 0 AND
Len(Field2) = 0) Then

If Len(Field1) > 0 AND Len(Field1) > 0 Then

In this situation, I assumed that the validation is simple in that the a
character is in either field. If the validation criteria is different,
adapting the above, shouldn't be that difficult.

For more on truth tables...

http://en.wikipedia.org/wiki/Truth_table

David H
 
Top