Results 1 to 8 of 8
  1. #1
    aellistechsupport is offline Competent Performer
    Windows 7 32bit Access 2013
    Join Date
    Apr 2014
    Posts
    410

    Nested IIFs?

    I am trying to return the result to where:
    If the ClassID = "ADMINFEE" AND the DateEnd field is NULL
    AND the PaidYear = this year then return as
    EndDate
    1. 6/30/thisyear


    Else
    2. 6/30/next year
    Else
    3. What's in DateEnd

    This is what I have but it's incorrect.
    Code:
    EndDate: IIf([ClassID]="ADMINFEE" And IsNull([DateEnd]),IIf([PaidYear]=Year(Date()),DateSerial(Year(Date()),6,30),DateSerial(Year(Date())+1,6,30)),[DateEnd])

  2. #2
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    This is what I have but it's incorrect.
    WHY is it incorrect?

    Is the field "[ClassID]" a text type or a number type field?

    Is the field "[PaidYear]" a text type or a number type field?

  3. #3
    aellistechsupport is offline Competent Performer
    Windows 7 32bit Access 2013
    Join Date
    Apr 2014
    Posts
    410
    Quote Originally Posted by ssanfu View Post
    WHY is it incorrect?

    Is the field "[ClassID]" a text type or a number type field?

    Is the field "[PaidYear]" a text type or a number type field?

    ClassID = "ADMINFEE" is text type field
    PaidYear = 2015 is a number field (converting PaymentDate with Year([PaymentDate]) as PaidYear

  4. #4
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    when you have uses lots of nested IF's then its time to either:

    make a lookup table to join to the data (this is the IF)
    or
    make a function

  5. #5
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Still don't know WHY the IIF() statement is incorrect.

    What is the data in 1 or 2 records?

    What does the query return for those records?


    Maybe post your dB?

  6. #6
    aellistechsupport is offline Competent Performer
    Windows 7 32bit Access 2013
    Join Date
    Apr 2014
    Posts
    410
    Oh, right, why I posted this as incorrect is that the result showed as such:

    A record has a paymentdate of 5/1/2015, so the PaidYear=2015
    The EndDate displayed (where the formula is) 6/30/2017, instead of 6/30/2016

  7. #7
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    So if the PaidYear is 2015, the end date should be in 2016?

    Maybe change
    DateSerial(Year(Date())+1,6,30)),

    to
    DateSerial(PaidYear+1,6,30)),


    Since the calculation is giving results, you just have to tweak it until it returns the correct results in all cases.

  8. #8
    aellistechsupport is offline Competent Performer
    Windows 7 32bit Access 2013
    Join Date
    Apr 2014
    Posts
    410
    Will try that.

    But see now where I didn't have it correct, this says if PaidYear = thisyear (2016), then 6/30/2016, else 2017
    IIf([PaidYear]=Year(Date()),DateSerial(Year(Date()),6,30),DateSe rialYear(Date())+1,6,30))

    this should now says if PaidYear = lastyear (2015), then 6/30/2016, else 2017
    IIf([PaidYear]=Year(Date())-1,DateSerial(Year(Date()),6,30),DateSerialYear(Date ())+1,6,30))

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

Similar Threads

  1. Nested IIFs?
    By aellistechsupport in forum Queries
    Replies: 15
    Last Post: 01-29-2016, 03:03 PM
  2. Criteria with IIFs?
    By aellistechsupport in forum Queries
    Replies: 15
    Last Post: 01-25-2016, 12:43 PM
  3. alternative to nested iifs
    By scotty22 in forum Queries
    Replies: 16
    Last Post: 06-28-2011, 09:21 AM
  4. Please help Query IIFs
    By nparrillo in forum Queries
    Replies: 7
    Last Post: 04-01-2011, 04:41 PM
  5. Multiple IIfs
    By SueO in forum Reports
    Replies: 1
    Last Post: 08-12-2010, 04: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