|
Question : Combining strings and converting to Date-Time...?
|
|
I am trying to create a report that lists transactions grouped by Month/Year. Each record to be listed on the report has a date associated with it, which is in DateTime format. However, to print the report, the user will have a brief form where they can choose the month/year parameters for the report -- they choose a StartMonth, StartYear, EndMonth, and EndYear (for example, run the report for transactions from May 2004 through January 2005). This form, then stores these four values in string variables (for the month names) and integer variables (for the years).
How do I go about combining and converting these variables into something I can then compare to the datetimes in the report's recordset, so as to filter the records for inclusion on the report??
|
|
Answer : Combining strings and converting to Date-Time...?
|
|
you could build a function to make dates from the form values and call the function directly in the query
SELECT * FROM myTable WHERE TransDate BETWEEN GetStartDate() AND GetEndDate
Public Function GetStartDate() As Date GetStartDate = CDate(strStartMonth & "/01" & strStartYear) End Function
Public Function GetEndDate() As Date Dim dtmEnd As Date dtmEnd = CDate(strEndMonth & "/01" & strEndYear) dtmEnd = DateAdd("mm", 1, dtmEnd) dtmEnd = dtmEnd - 1 GetEndDate = dtmEnd End Function
Steve
|
|
|
|