View Single Post
  #2  
Old April 28th, 2010, 08:02 PM posted to microsoft.public.access.queries
vanderghast
external usenet poster
 
Posts: 593
Default Change expression from month to quarter

assuming you have a dateTime and not a string, you can change the comparison
to test the year and the quarter:

iif( Year(transDate) = Year( CDate(FORMS!frmVarianceQtr!txtMo1) )
AND DatePart("q", transDate) = DatePart("q",
CDate(FORMS!frmVarianceQtr!TxtMo1 )) ,

ODC_cost,

0 )



You could also have tested:

iif( Format( transDate, "yyyyq") = Format( CDate(
FORMS!frmVarianceQtr!txtMo1 ), "yyyyq"),
ODC_cost,
0)


but using strings is generally slower.



Vanderghast, Access MVP


"AccessKay" wrote in message
...
I have this expression in a calculated field in my query and it works fine
for the month. I enter the month via a text box on an unbound form. I
thought that if I changed the “m” to a “q” that it would calculate the
quarter based on the date that I supply in my text box. It works if the
month is the first month in the quarter but if it’s like Feb or March, it
returns the wrong amount. Can anyone help me fix this so that it pulls
the
correct quarter total?

Qtr_1: Sum(IIf([TransDate] Between ([Forms]![frmVarianceQtr]![txtMo1]) And
DateAdd("q",1,([Forms]![frmVarianceQtr]![txtMo1]))-1,[tblTrans_Mstr].[ODC_Cost],0))

TransDate is in datetime mm/dd/yyyy format

I appreciate any help!