Results 1 to 7 of 7
  1. #1
    Purdue_Engineer is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2012
    Posts
    9

    Comparing Dates in nested IIF statements


    I want to return a value based on a date being within a date range. For example, if a date is between 01/01/12 and 01/31/12, the expression returns "1", if the date is between 02/01/12 and 02/29/12 , then "2", etc. I am using: IIf([ActualPickupDate]=Between #01/01/12# And #01/31/12#,1, IIf([ActualPickupDate]=Between #02/01/12# And #02/29/12#,2,... And #12/31/12#, 12,""))))))))))))

    I keep getting syntax errors. Any suggestions?

    Thanks

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    Just a quick note here if you set your query up this way you're going to have to change the formulas every year to match the current year which is going to be a ton of maintenance but you don't need the = sign after [actualpickupdate] it would just be:

    iif([ActualPickupDate] between #1/1/2012# and #1/31/2012#, 1, iif([actualpickupdate] between #2/1/2012# and #2/29/2012#, 2, etc...))

  3. #3
    Purdue_Engineer is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2012
    Posts
    9
    Ok thanks for the info.

    I see that would be a lot of maintenance. Could you recommend a way to get around having to update the query for every year?

  4. #4
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    If you're just trying to extract the month it's much more simple:

    datepart("m", [ActualPickupDate])

  5. #5
    Purdue_Engineer is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2012
    Posts
    9
    That would work great. I am trying to use that in the same table as a Calculated Field but the expression is not allowed. Can I not use this in a table?

  6. #6
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    I don't know what you mean, tables should not be storing calculated values, ever. You would use this formula in a query or form then use it to look up whatever else you wanted. If I'm reading this right you need to know what the month is to look up another value and then perform a calculation based on that looked up value? That can all be done with queries and storing a calculated value in a table is a horribly bad idea.

  7. #7
    Purdue_Engineer is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2012
    Posts
    9
    Ok I will put into a query.

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

Similar Threads

  1. Comparing dates
    By shanky365 in forum Queries
    Replies: 2
    Last Post: 10-26-2011, 01:28 AM
  2. Replies: 3
    Last Post: 09-14-2011, 05:27 PM
  3. Nested If Statements Using Or (Logic Error)
    By IFA Stamford in forum Access
    Replies: 7
    Last Post: 12-30-2010, 08:53 AM
  4. Nested Select Statements in FROM clause
    By neonslip in forum Queries
    Replies: 11
    Last Post: 11-03-2010, 10:58 AM
  5. Nested IIF statements?
    By laavista in forum Access
    Replies: 9
    Last Post: 06-22-2010, 10:35 AM

Tags for this Thread

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