Results 1 to 8 of 8
  1. #1
    WAVP375 is offline Competent Performer
    Windows 8 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Dayton Ohio
    Posts
    171

    IIf function in a query

    A query containing two fields, [CertificationExpiration] and [LifeTimeCertification] where only one of the fields will contain data and the other will be blank. In a query I am attempting to create a field called CertDate: which will contain the content of which ever field is populated. I am using the following statement. I get the false value but cannot get the true value.



    CertDate: IIf([LifeTimeCertification]=Null,[CertificationExpiration],[LifeTimeCertification])

    I have turn the statement around and interigated the CertificationExpiration field and get the same results, no value when true.

    What am I overlooking

    Thanks

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,526
    you dont = NULL, you must use a function

    IIf([ISNULL(LifeTimeCertification]),[CertificationExpiration],[LifeTimeCertification])

  3. #3
    WAVP375 is offline Competent Performer
    Windows 8 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Dayton Ohio
    Posts
    171
    I copied and pasted you expression and i get an error saying 'wrong number of arguements"

  4. #4
    Join Date
    Apr 2017
    Posts
    1,683
    Quote Originally Posted by WAVP375 View Post
    CertDate: IIf([LifeTimeCertification]=Null,[CertificationExpiration],[LifeTimeCertification])
    CertDate: IIf(Nz([LifeTimeCertification],0)=0,[CertificationExpiration],[LifeTimeCertification])

  5. #5
    WAVP375 is offline Competent Performer
    Windows 8 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Dayton Ohio
    Posts
    171
    Both true and false returns #ERROR

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,942
    Ranman has a typo with misplaced [ in front of ISNULL.

    IIf(ISNULL([LifeTimeCertification]),[CertificationExpiration],[LifeTimeCertification])

    Simpler structure:
    Nz([LifeTimeCertification], [CertificationExpiration])

    However, I see no reason for cause of #ERROR in the already suggested Nz expression as syntax is correct, so whatever the cause, will probably occur for any of the suggestions.

    Review: http://allenbrowne.com/QueryPerfIssue.html

    This calc can also be done in textbox on form or report.

    An alternative table structure would have a single field for date and another field (could be Yes/No) to flag the date as a lifetime certification.
    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.

  7. #7
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Just curious.... what do you do if/when both are Null??? I don't yet have a certification, nor a LifeTimeCertification...

  8. #8
    WAVP375 is offline Competent Performer
    Windows 10 Access 2013 32bit
    Join Date
    Jul 2015
    Location
    Dayton Ohio
    Posts
    171
    Thanks guys, I got it worked out. Fortunatly there is always more than one way to skin a cat.

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

Similar Threads

  1. Query with IIF Function
    By MSdove1 in forum Queries
    Replies: 6
    Last Post: 04-03-2017, 06:07 PM
  2. Sum function within query
    By Vinagray@gmail.com in forum Reports
    Replies: 9
    Last Post: 10-14-2016, 04:23 PM
  3. Function won't run in a Query
    By Paul H in forum Programming
    Replies: 12
    Last Post: 07-08-2015, 12:16 PM
  4. VBA function query
    By Pacific1 in forum Programming
    Replies: 1
    Last Post: 12-04-2014, 01:19 PM
  5. Replies: 4
    Last Post: 11-19-2010, 07:21 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