Question

Is this valid in MS Access VBA:

iif ([company] = "starbucks", "retail", iif ([item] <> "", "DLookup(....)", ""))

I'm trying to get something similar to the above work.

Was it helpful?

Solution

Yes.

You can nest up to 14 IIf statements before Jet/ACE complains that the "Expression is too complex." There is no similar limitation on the VBA IIf function.

Since you are using this in the Control Source of the form, Access will evaluate this using its Expression Service (which essentially treats it as though it were part of a Jet/ACE query) so the 14 levels of nesting limit will apply.

Note also that I referred to the Jet/ACE IIf as a statement and the VBA IIf as a function. While those terms are sometimes used loosely, they have precise meaning. The IIf statement of Jet/ACE is a true ternary operator. The upshot is that it is generally more efficient than the VBA function of the same name and it does not suffer from potential side effects.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top