How to use MS Access expression builder for if fieldA value = " then fieldB = "

1.8k Views Asked by At

Using MS Access expression builder for if fieldA value = " then fieldBdate = " table name is myOrder; myOrder has several fields including fieldA text (using value list for value selection, of which "Received" is one); And another field is named fieldBdate of DateTime type.

either
iif (fieldA] = "Received",[ fieldBDate] = Date(), null);
or 

if ([fieldA] = "Received" then[ fieldBdate] = Date()

failed to meet with Access expression syntax

with both Access 2000 and Access 2010. What's the correct syntax?

Thanks.

1

There are 1 best solutions below

2
dbmitch On

Time for you to learn how to use built-in VBA manual with Intellisense and even basic google search of IIf syntax

How to use:

IIF( <test-for-condition>, <value if true>, <value if false> )

In your case:

FieldBDate = IIf([FieldA] = "Received", Date(), Null)

EDIT - Based upon your comment that you want to set Default Value

You cannot set the Default Value expression based on another field in a table design. Think about it - there's no way that Access knows what the other field's value is until it's actually entered.

What you need to do is add the above code to your FieldA_AfterUpdate event