Results 1 to 3 of 3
  1. #1
    rbennion is offline Novice
    Windows 7 32bit Access 2013 32bit
    Join Date
    Jun 2017
    Posts
    17

    Help a noob understand IIF

    Hey all,



    I am quite familiar with CASE, much to my dismay I have discovered Access doesn't support CASE. So, I have been referred to IIF statements instead. I actually have my query working, I just want to understand how its working. lol.

    All I want to do is only populate the "Enrollment_Date" field if there is a value, if its null I don't want it. Below is the code of how I have done this (bolded and underlined).

    SELECT DatePart ("yyyy", [Referral_Date]) AS [Year], DatePart ("m", [Referral_Date]) AS [Month],
    Count(IIf(Enrollment_Date IS NULL,1)) AS NoShowPatients, Count(General.Referral_Date) AS ReferredPatients, Round([NoShowPatients]/[ReferredPatients],2) AS NoShowRate
    FROM [General]
    GROUP BY DatePart ("yyyy", [Referral_Date]), DatePart ("m", [Referral_Date]);

    Is Access interpreting the "1" in the "value if true" criteria as a literal 1 so it adds them up to give me my COUNT? And why am I able to leave the "value if false" empty entirely?

    Thanks for any response, I know this is probably rudimentary.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,527
    access DOES supports CASE in vb, queries do not.
    in queries you can use IIF, or SWITCH, or use a lookup table.

    but you shouldnt use IIF in a count. Put the iif in a query, THEN count them in another query.

  3. #3
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,967
    Seems the false argument of IIf in query defaults to Null. Nulls are not aggregated. Do a test by putting a value (any value - 5, 'a', 'None') in the argument and see what happens, then use Null. Can also put any value in the true argument and the output will be the same as using 1.

    An alternative is: Sum(IIf(Enrollment_Date Is Null, 1, 0))

    or if you don't even want 0 to return: Sum(IIf(Enrollment_Date Is Null, 1)) - again the false argument defaults to Null and gives the same output as explicitly referencing Null.

    VBA appears to require the false argument to be explicit but an expression in textbox managed without.
    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. I do not understand the steps
    By Lou_Reed in forum Access
    Replies: 4
    Last Post: 07-23-2015, 11:20 AM
  2. Trying to Understand Relationships
    By Bkper087 in forum Access
    Replies: 3
    Last Post: 10-10-2014, 12:42 AM
  3. Someone to help me understand a guide
    By carrybag93 in forum Access
    Replies: 4
    Last Post: 06-04-2012, 12:20 AM
  4. Need to understand code
    By accessnewb in forum Programming
    Replies: 2
    Last Post: 08-03-2011, 12:03 PM
  5. Help me to understand forms
    By RTaylor in forum Forms
    Replies: 0
    Last Post: 04-10-2010, 01:36 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