Share via

Access 2007: Using if/null expression for two fields

Anonymous
2012-07-24T22:21:27+00:00

I have two fields A and B and am in need to build an expression to populate Field C. Basically I need it to populate to field A unless field A is null. If field A is Null then field B should populate instead.

In excel this is what my formula would look like:

=IF(ISBLANK(A1),B1,A1)

Now as I try to build an expression in access I am having no such luck. I have used everything from

IIf(IsNull[A],[B],[A])

to:

IIf((IsNull([A])),(IIF(IsNotNull([A])), [A],[B]),[A])

Is there something that I am missing? I hope this simplifed version of my issue makes sense. I appreciate the help.

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

6 answers

Sort by: Most helpful
  1. HansV 462.6K Reputation points
    2012-07-25T16:19:47+00:00

    I don't see a reason to store it in the table. It is derived information that can be calculated on the fly in a query based on the table.

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2012-07-25T15:57:46+00:00

    I tried that as well initially but had no such luck. Here is my actual expression with Product Code as Field A and Product Interest (1) as Field B. Fortunately the Nz Expression worked. Thank you for the help.

    Adj Prod: IIf((IsNull([Product Code])),(IIF(IsNull([Product Code])), [Product Code],[Product Interest (1)]),[Product Code])

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2012-07-25T15:54:59+00:00

    Thank you. A follow up question, however:

    Is it safe to store that expression in a field in the table?

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2012-07-25T11:18:39+00:00

    Nz should works fine, but instead of IIf(IsNull[A],[B],[A]), you could have tried  iif( IsNull**(** [A] ),  [B], [A] ). You were missing the ( ) for  IsNull.

    Was this answer helpful?

    0 comments No comments
  5. HansV 462.6K Reputation points
    2012-07-24T23:04:32+00:00

    Try this in a query:

    C: Nz([A], [B])

    Was this answer helpful?

    0 comments No comments