The following applies to Access 2003 on MS XP Pro
On a form, I have a field [CurrIspQtr] that needs to give a count in 3-month periods, between the current date and a begin date which could be any date of the year. That is: the required Result is the number of quarters from date X to today [Date()].
An "ISP Year" is the 1-year period that may start on any date. That is: If the ISP Year starts on Feb. 23, 2011, the ISP year ends on Feb. 22, 2012. So any date from Feb. 23, 2011 to April 22, 2011 in this example would be Qtr 1 of the ISP year. That is, the current quarter between 02/23/11 and 04/22/11 is Qtr 1, or [CurrISPQtr] = 1. April 23 would start Qtr 2, and so on. If today was March 15, 2012 in this example, we would would be in Qtr 5 relative to the ISP year starting on Feb. 23, 2011.
ISPEffecFrom is the start date of the ISP Year. So I have tried:
=DateDiff("q",[ISPEffecFrom],Date())
Where [ISPEffecFrom] is the start date of the ISP Year.
The above code intended to produce the desired result, is the Control Source for a text box named [CurrISPQtr] and labeled 'Current ISP Quarter.'
But the above code often produces erroneous results. It appears "q" in Access only calculates quarters based on begin dates 01/01, 04/01, 07/01, and 12/01.
Thus, relative to today's date of March 24, 2011:
If the start date of the ISP year( [ISPEffecFrom] )was 09/30/11, the calculation correctly returns '2' as the Current ISP Quarter. BUT, if the start date is 10/01/10, the above code gives an INCORRECT result of '1' as the Current ISP Quarter.
Further: Relative to Date() = 03/24/11, if the ISP Year started 12/01/11, the above DateDiff code gives a result of '0' for [CurrISPQtr] when the correct result should be that we are in ISP Qtr '1'.
I tried replacing 'q' with ('m' *3) but ended up with a data type error.
I have racked my brain examining other Date functions and digging around the internet, but have not been able to come up with anything that defeats Access's interpretation of date-quarters. It appears I have to find a way, possibly in a VBA module, of counting raw 3-month periods between dates instead of quarters; then rounding _down_ to the nearest whole Positive integer (so it would never = 0 which is neither positive nor negative): But I have no real training or expertise as to SQL or VBA, only what I've taught myself thru trial and error -- and I'm lost. Help?
C. Reyes
On a form, I have a field [CurrIspQtr] that needs to give a count in 3-month periods, between the current date and a begin date which could be any date of the year. That is: the required Result is the number of quarters from date X to today [Date()].
An "ISP Year" is the 1-year period that may start on any date. That is: If the ISP Year starts on Feb. 23, 2011, the ISP year ends on Feb. 22, 2012. So any date from Feb. 23, 2011 to April 22, 2011 in this example would be Qtr 1 of the ISP year. That is, the current quarter between 02/23/11 and 04/22/11 is Qtr 1, or [CurrISPQtr] = 1. April 23 would start Qtr 2, and so on. If today was March 15, 2012 in this example, we would would be in Qtr 5 relative to the ISP year starting on Feb. 23, 2011.
ISPEffecFrom is the start date of the ISP Year. So I have tried:
=DateDiff("q",[ISPEffecFrom],Date())
Where [ISPEffecFrom] is the start date of the ISP Year.
The above code intended to produce the desired result, is the Control Source for a text box named [CurrISPQtr] and labeled 'Current ISP Quarter.'
But the above code often produces erroneous results. It appears "q" in Access only calculates quarters based on begin dates 01/01, 04/01, 07/01, and 12/01.
Thus, relative to today's date of March 24, 2011:
If the start date of the ISP year( [ISPEffecFrom] )was 09/30/11, the calculation correctly returns '2' as the Current ISP Quarter. BUT, if the start date is 10/01/10, the above code gives an INCORRECT result of '1' as the Current ISP Quarter.
Further: Relative to Date() = 03/24/11, if the ISP Year started 12/01/11, the above DateDiff code gives a result of '0' for [CurrISPQtr] when the correct result should be that we are in ISP Qtr '1'.
I tried replacing 'q' with ('m' *3) but ended up with a data type error.
I have racked my brain examining other Date functions and digging around the internet, but have not been able to come up with anything that defeats Access's interpretation of date-quarters. It appears I have to find a way, possibly in a VBA module, of counting raw 3-month periods between dates instead of quarters; then rounding _down_ to the nearest whole Positive integer (so it would never = 0 which is neither positive nor negative): But I have no real training or expertise as to SQL or VBA, only what I've taught myself thru trial and error -- and I'm lost. Help?
C. Reyes