Results 1 to 5 of 5
  1. #1
    jgelpi16 is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544

    Question What's wrong with this filter?

    My ultimate goal is to run code block #2....However, it will not produce any results currently (this is a criteria in a query). IF I run code block #1 the results display as desired....What is wrong with my IIF statement in code block #2? I have been staring at this thing for entirely too long. Any help is much appreciated!

    Code block #1


    Code:
    Between CDate(DatePart("m",Date())-1 & "/1/" & DatePart("yyyy",Date())) And CDate(DatePart("m",Date())-1 & "/31/" & DatePart("yyyy",Date()))
    Code block #2
    Code:
    IIf(DatePart("m",Date())=1,Between CDate("12/1/" & DatePart("yyyy",Date())-1) And CDate("12/31/" & DatePart("yyyy",Date())-1),Between CDate(DatePart("m",Date())-1 & "/1/" & DatePart("yyyy",Date())) And CDate(DatePart("m",Date())-1 & "/31/" & DatePart("yyyy",Date())))

  2. #2
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    Quote Originally Posted by jgelpi16 View Post
    Code:
    Between CDate(DatePart("m",Date())-1 & "/1/" & 
    
    DatePart("yyyy",Date())) And CDate(DatePart("m",Date())-1 & 
    
    "/31/" & DatePart("yyyy",Date()))
    Code block #2
    Code:
    IIf(DatePart("m",Date())=1,Between CDate("12/1/" & 
    
    DatePart("yyyy",Date())-1) And CDate("12/31/" & 
    
    DatePart("yyyy",Date())-1),Between CDate(DatePart("m",Date())-1 
    
    & "/1/" & DatePart("yyyy",Date())) And CDate(DatePart("m",Date())-1 
    
    & "/31/" & DatePart("yyyy",Date())))
    The problem might be the fact that you can't have a 'between' statement inside of an IIF() statement. As a matter of fact, just looking at it, logically, it doesn't make sense, and probably would look invalid to the parser. I'm 99% sure that's it.

    And as a side note, think about the args in an IIF(). They are:

    • arg
    • value if true
    • value if false


    a 'between' statement can't possibly be evaluated back to a value, hence the statement is invalid.

  3. #3
    jgelpi16 is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    I do understand that...I thought this would logically work because I'm using the "BETWEEN" statements as the true and false "values"...

    Code:
    IIf(DatePart("m",Date())=1,Between CDate("12/1/" & 
    
    DatePart("yyyy",Date())-1) And CDate("12/31/" & 
    
    DatePart("yyyy",Date())-1),Between CDate(DatePart("m",Date())-1 
    
    & "/1/" & DatePart("yyyy",Date())) And CDate(DatePart("m",Date())-1 
    
    & "/31/" & DatePart("yyyy",Date())))

  4. #4
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    No, try something like this instead:
    Code:
    BETWEEN IIf(DatePart("m",Date())=1, CDate("12/1/" & DatePart("yyyy",Date())-1),
    
    CDate(DatePart("m",Date())-1 & "/1/" & DatePart("yyyy",Date())))
    
    AND IIf(DatePart("m",Date())=1, CDate("12/31/" & DatePart("yyyy",Date())-1),
    
    CDate(DatePart("m",Date())-1 & "/31/" & DatePart("yyyy",Date())))
    That's exactly the same thing, just parsable by the program.

  5. #5
    jgelpi16 is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    Ok, will do. Thanks a lot.

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

Similar Threads

  1. What is wrong with my listbox?
    By Buakaw in forum Access
    Replies: 4
    Last Post: 02-21-2011, 03:08 PM
  2. Replies: 6
    Last Post: 10-12-2010, 09:35 AM
  3. What's wrong with this query?
    By jsoldi in forum Queries
    Replies: 2
    Last Post: 10-11-2010, 07:45 AM
  4. What is wrong with this code?
    By nkenney in forum Forms
    Replies: 2
    Last Post: 11-16-2009, 03:04 PM
  5. What am I doing wrong?
    By brandon in forum Access
    Replies: 2
    Last Post: 08-03-2008, 10:26 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