Access VBA:IIF function Sample of multiple conditional nesting

Published on:
Last updated:

This post is also available in: Japanese

When writing IIF function nested code in Access VBA, I often forget it, so write it instead of a memo.

The definition of the IIF function is as follows.

If [Condition] is mutch, [Return Value in case of True] is returned. If not, [Return Value in case of False] is returned.
IIf( [Condition], [Return Value in case of True] , [Return Value in case of False] )

For example, when calculating the total value of values that match multiple conditions of IIf, it will look like the sample code below.
If [Condition A] is match and [Condition B] is match, [Return Value in case of True] is returned, and the total value of [Return Value in case of True] is calculated.

Sum(IIf([Condition A], IIf([Condition B], [Return Value in case of True])))

Of course, multiple conditions can be combined in the same way.
The Switch function is useful when you want to perform True/False judgment by picking up specific conditions.

No tags for this post.

Kuniyoshi Takemoto is the founder of LLC, and editor of this blog( more and follow me on LinkedIn.