I have a query that will create a report. The SQL statements that comprise this query are a series of 5 Union statements broken out by date ranges. The last part of each of the SQL statements in each of the Unions are as follows:
The first union is for a date range within the last 6 months:
... WHERE (((C.DateLost) Between #8/1/2004# And #1/31/2005#))
The second union is for a date range from 6 months to 1 year ago:
... WHERE (((C.DateLost) Between #2/1/2004# And #7/31/2004#))
------------------------------------------------------
The user clicks a "Run Report" Command Button and then the application executes the query which generates the report.
I used the following statement to execute the query:
Set rstQueryFS = CurrentProject.Connection.Execute("qryCuPFQ", , adCmdStoredProc)
The issue is that the date ranges I have hard coded need to taken out of the query and replaced by variable date ranges.
When the user runs the report based on this query,
I want to check and see if the current date is the last day of the month. For ex: if today was 1/31/05 then the following dates are acccurate with the 1st sql statement:
... WHERE (((C.DateLost) Between #8/1/2004# And #1/31/2005#))
However, if the current date was other than the last day of the month, for example, if today was 1/14/2005, then I would use the last date of the prior month (for ex: 12/31/2004) as my starting Between date.
... WHERE (((C.DateLost) Between #7/1/2004# And #12/31/2004#))
Instead of using the Passing Parameters feature of Forms in which the user would plug in the current (run) date to allow for the determination of the date ranges within the 5 unions, is there another way to run the report with variable dates for the BETWEEN starting and ending dates within each of the 5 Union statements of my query ?
I was thinking that the Immediate If function could make a comparison of today's date vs. the current month end date as follows:
IIf (Date = (DateSerial(Year(Date),Month(Date)+1,0)
I guess another option would be to breakout the SQL code into a long string and use date variables.
The first union is for a date range within the last 6 months:
... WHERE (((C.DateLost) Between #8/1/2004# And #1/31/2005#))
The second union is for a date range from 6 months to 1 year ago:
... WHERE (((C.DateLost) Between #2/1/2004# And #7/31/2004#))
------------------------------------------------------
The user clicks a "Run Report" Command Button and then the application executes the query which generates the report.
I used the following statement to execute the query:
Set rstQueryFS = CurrentProject.Connection.Execute("qryCuPFQ", , adCmdStoredProc)
The issue is that the date ranges I have hard coded need to taken out of the query and replaced by variable date ranges.
When the user runs the report based on this query,
I want to check and see if the current date is the last day of the month. For ex: if today was 1/31/05 then the following dates are acccurate with the 1st sql statement:
... WHERE (((C.DateLost) Between #8/1/2004# And #1/31/2005#))
However, if the current date was other than the last day of the month, for example, if today was 1/14/2005, then I would use the last date of the prior month (for ex: 12/31/2004) as my starting Between date.
... WHERE (((C.DateLost) Between #7/1/2004# And #12/31/2004#))
Instead of using the Passing Parameters feature of Forms in which the user would plug in the current (run) date to allow for the determination of the date ranges within the 5 unions, is there another way to run the report with variable dates for the BETWEEN starting and ending dates within each of the 5 Union statements of my query ?
I was thinking that the Immediate If function could make a comparison of today's date vs. the current month end date as follows:
IIf (Date = (DateSerial(Year(Date),Month(Date)+1,0)
I guess another option would be to breakout the SQL code into a long string and use date variables.