Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Criteria question using iif statement 2

Status
Not open for further replies.

ccurt

Technical User
Apr 11, 2013
4
US
Is there a reason I get no results in the date field using this statement for my criteria? I'm guessing something is wrong with my expression DatePart("d",date())=1

IIf(DatePart("d",Date())=1,>=DateSerial(Year(Date()),Month(Date())-1,1) And <Date(),>=DateSerial(Year(Date()),Month(Date()),1) And <Date())

If there's a better way to do this I would greatly appreciate it. Bacically I'm looking current month dates from 1st to current date of this month and when the current date is the 1st of the month use dates from the previous month 1st through the end of the month. Thanks!
 
Your true part and false part of your IIF are funky... What I think you are saying you want to do looks like this for the where clause....

Code:
Where <SomeDate> 
      Between IIF(DatePart("d",Date())=1,DateSerial(Year(Date()),Month(Date())-1,1),DateSerial(Year(Date()),Month(Date()),1)) 
              AND IIF(DatePart("d",Date())=1,Dateadd("d",-1, Date()), Date())
 
Thanks, that works perfectly for what I need.
 
I'm new to this site, definitely deserves a star. Thanks again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top