access 2007 create expression for Quarter date query

I want to sort date fields for period for a query
the date is last quarter date to the present date

What is the expression for a query for the above please
topUKlawyerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Gustav BrockCIOCommented:
Here is a function to use:
Public Function DatePreviousQuarterLast( _
  Optional ByVal datDateThisQuarter As Date) As Date
  
  Const cintQuarterMonthCount   As Integer = 3
  
  Dim intThisMonth              As Integer
  
  If datDateThisQuarter = 0 Then
    datDateThisQuarter = Date
  End If
  intThisMonth = (DatePart("q", datDateThisQuarter) - 1) * cintQuarterMonthCount
  
  DatePreviousQuarterLast = DateAdd("q", 0, DateSerial(Year(datDateThisQuarter), intThisMonth + 1, 0))

End Function

Open in new window


Thus your criteria could be (to include both dates):

  where [YourDateField] between DatePreviousQuarterLast() and Date()

or to exclude these:

  where [YourDateField] > DatePreviousQuarterLast() and  [YourDateField] < Date()

/gustav
0
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
There is no builtin function for that. You would need to "assign" a period, based on the Month value of your Date field:

Period: SWITCH((Month(YourDateField)>9, 4, Month(YourDateField)>6, 3,  Month(YourDateField)>3, 2, Month(YourDateField)>0,1)

This would add a new field named "Period" to your query.

0
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
Sorry ... didn't read this one correctly.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

topUKlawyerAuthor Commented:
Thanks guys,

have I asked accurately?

If say todays date is 30 October, which it is,  i need to select dates between 1st October  and now. should I have said present quarter date and now?

if todays date were 30 Sept then select 1st July to 30th Sept?

0
Gustav BrockCIOCommented:
Then use this function:
Public Function DateThisQuarterFirst( _
  Optional ByVal datDateThisQuarter As Date) As Date
  
  Const cintQuarterMonthCount   As Integer = 3
  
  Dim intThisMonth              As Integer
  
  If datDateThisQuarter = 0 Then
    datDateThisQuarter = Date
  End If
  intThisMonth = (DatePart("q", datDateThisQuarter) - 1) * cintQuarterMonthCount

  DateThisQuarterFirst = DateSerial(Year(datDateThisQuarter), intThisMonth + 1, 1)

End Function

Open in new window


/gustav
0
topUKlawyerAuthor Commented:
Thanks, if I might ask, what does the integers 0 through to 3 represent exactly?
0
Gustav BrockCIOCommented:
cintQuarterMonthCount  is the month count for a quarter (= 12 / 4)

datDateThisQuarter is 0 (the default numeric value of data type Date) if no value is supplied for this parameter.

/gustav
0
topUKlawyerAuthor Commented:
Thanks, just to be sure what my query criteria would be?

0
Gustav BrockCIOCommented:
As I wrote above:

  Between DateThisQuarterFirst() And Date()

/gustav
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
topUKlawyerAuthor Commented:
sounds good. will try and if any probs report back,

many thanks
0
Gustav BrockCIOCommented:
You are welcome!

/gustav
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Applications

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.