Results 1 to 4 of 4
  1. #1
    Remster is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Sep 2010
    Posts
    317

    Managing null values: IIf or Nz or ...?

    Folks

    To avoid problems with functions like Replace, InStr or ConcatRelated, I'm accustomed to using IIf:



    IIf([MyField] Is Not Null, Replace([MyField],"A","B"),"")

    This seems like a bit of a faff, so I was wondering if there was a better way. I've just discovered 'Nz'. Is that the best option?

    Thanks

    Remster

  2. #2
    JeffChr is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Feb 2014
    Posts
    82
    nz has the added functionality of substituting a value for the null. i use it all the time.

  3. #3
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    But thats exactly what you did...you used the REPLACE funtion in the if.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    It can simplify the expression.

    Replace(Nz([field],""),"A","B")

    However, if you don't want an empty string result, use the IIf but use IsNull

    IIf(IsNull([field]), Null, Replace(Nz([field],""),"A","B")
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 7
    Last Post: 12-04-2013, 01:55 PM
  2. calcs with null values
    By mike02 in forum Queries
    Replies: 5
    Last Post: 08-13-2013, 09:12 AM
  3. Finding the Max Date and Null Values if Null
    By SpdRacerX in forum Queries
    Replies: 1
    Last Post: 02-03-2012, 06:29 AM
  4. null values
    By ippy in forum Queries
    Replies: 3
    Last Post: 12-20-2010, 10:39 AM
  5. HELP with NULL DateTime VALUES
    By lfolger in forum Programming
    Replies: 3
    Last Post: 03-28-2008, 02:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums