ZigZagZak said:
Hello-
I need a query to find all entries within the current fiscal year (starting
July 1st to June 30th). So if the date I search for is July 30th I only want
it to find the results for that month. If I say June 30th. It would be for
the past 12 months.
Thanks in advance.
Zach K.
ZZZK:
How about a function whose input is a date within the year and a test
date whose output is a boolean indicating whether or not the test date
is within the fiscal year. Then you could use the function in a query
with the criterion '= -1' to return only the records with a date during
that fiscal year. Then add the condition that the test date is on or
before the search date.
'pseudosql:
e.g., SELECT InFiscalYear(dtInFiscalYear, [InvoiceDate]) As ToSelect,
.... WHERE ToSelect = -1 AND [InvoiceDate] <= dtInFiscalYear;
'module air code:
Public Function InFiscalYear(dtInFiscalYear As Date, dtTest As Date) As
Boolean
Dim dtFYStart As Date
Dim dtFYEnd As Date
'July 1 to June 30
If Month(dtInFiscalYear) >= 7 Then
dtFYStart = DateSerial(Year(dtInFiscalYear), 7, 1)
dtFYEnd = DateSerial(Year(dtInFiscalYear) + 1, 6, 30)
Else
dtFYStart = DateSerial(Year(dtInFiscalYear) - 1, 7, 1)
dtFYEnd = DateSerial(Year(dtInFiscalYear), 6, 30)
End If
If dtTest >= dtFYStart And dtTest <= dtFYEnd Then
InFiscalYear = True
Else
InFiscalYear = False
End If
End Function
or using SQL only with a search date from a form:
'SQL air code
SELECT * FROM table WHERE [InvoiceDate] <=
Forms!frmMain!DateInFiscalYear AND
IIf(Month(Forms!frmMain!DateInFiscalYear) >= 7, [InvoiceDate] BETWEEN
DateSerial(Year(Forms!frmMain!DateInFiscalYear), 7, 1) AND
DateSerial(Year(Forms!frmMain!DateInFiscalYear) + 1, 6, 30),
[InvoiceDate] BETWEEN DateSerial(Year(Forms!frmMain!DateInFiscalYear) -
1, 7, 1) AND DateSerial(Year(Forms!frmMain!DateInFiscalYear), 6, 30)) = -1
These seem to do what you are asking for. Maybe a parameter in the
query would be better than referencing the form field five times.
James A. Fortune
(e-mail address removed)