Validation rule to prevent entry

S

simonc

I am designing a table in which one field has two possible values, and a
second field must be filled if the first field has one value, and must be
empty if the first field has the other value. (Hope that makes sense.)

How can I implement this? Is there some expression I can put in the
validation rule which will enforce this?

Grateful for any help
 
O

Ofer Cohen

You can do that using a form to enter data in the table.

On the Before update event of the form, you can add the code to validate the
entry

If Me.Field1 = "Value1" And Len(Me.Field2 & "")=0 Then
MsgBox "Field2 must be filled"
Else
If Me.Field1 = "Value2" Then
Me.Field2 = Null
End If
End If
 
O

Ofer Cohen

I forgot one thing

If Me.Field1 = "Value1" And Len(Me.Field2 & "")=0 Then
MsgBox "Field2 must be filled"
Cancel = True 'wont let the user exit until the field is filled
Else
If Me.Field1 = "Value2" Then
Me.Field2 = Null
End If
End If
 
Top