Results 1 to 5 of 5
  1. #1
    DavidQMP is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2016
    Posts
    8

    Using ISNULL and SWITCH functions

    Hi,

    Is there anyway to include ISNULL in the below? I want to replace null values with a 0 and the last element of the below doesn't work.



    (Switch([Rating]="1","0.2",[Rating]="2","0.4",[Rating]="3","0.6",[Rating]="4","0.8",[Rating]="5","1",[Rating]=" ","0")

    Thanks in advance

  2. #2
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    You can use the NZ function to replace Null values with zero, i.e.
    NZ([Rating],0)
    will return the value from Rating, but if the field is Null, it will return whatever you tell it to in the second argument (0 in our example).

  3. #3
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Easier would be to use :

    nz([Rating],0) / 5.0 - you don't need switch at all.

    PS - the reason your original statement didn't work is that " " isn't Null - it's a string of one blank. "" isn't Null either - it's an empty string.

  4. #4
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,932
    if you just want a default when rating isn't 1-5, then just use True (no quotes) instead of 'rating=" "''

  5. #5
    DavidQMP is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2016
    Posts
    8
    Quote Originally Posted by JoeM View Post
    You can use the NZ function to replace Null values with zero, i.e.
    NZ([Rating],0)
    will return the value from Rating, but if the field is Null, it will return whatever you tell it to in the second argument (0 in our example).
    Thank you very much, I nested the switch functions within a Nz function.

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

Similar Threads

  1. Switch with custom functions giving #ERROR
    By bogzla in forum Queries
    Replies: 2
    Last Post: 03-11-2016, 03:30 AM
  2. isnull and not isnull
    By webisti in forum Programming
    Replies: 11
    Last Post: 03-04-2014, 08:44 AM
  3. IIF IsNull
    By angie in forum Forms
    Replies: 11
    Last Post: 12-17-2013, 02:25 PM
  4. Using Between with iif isnull
    By TonyB in forum Queries
    Replies: 5
    Last Post: 09-03-2013, 09:56 AM
  5. If IsNull Value, Then need to be Zero
    By burrina in forum Forms
    Replies: 2
    Last Post: 11-18-2012, 02:53 AM

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