I have a requirement to provide a dropdown Date Option providing the following:
- Custom - allow date entry or using the Calendar control
- YTD - populate the StartDate & EndDate parameters with the 1st of January to today
- MTD - populate the StartDate & EndDate parameters with the 1st day of Month to today
- QTD - populate the StartDate & EndDate parameters with the 1st day of Qtr to today
etc
Using a Custom Code VB script to provide the Date for both the Start & End Date.
Function GetStartDate(ByVal intChoice As Integer) as Date
Select Case intChoice
Case 0
GetStartDate = Nothing
Case 1
GetStartDate = DateSerial(YEAR(Today), 1, 1)
Case 2
GetStartDate = DateSerial(YEAR(Today), MONTH(DateAdd(DateInterval.Quarter, 0, Today)), 1)
Case 3
GetStartDate = DateSerial(YEAR(Today), MONTH(Today), 1)
Case 4
GetStartDate = DATEADD(DateInterval.Month, -12, Today)
Case 5
GetStartDate = DATEADD("m",-1,dateserial(year(Today),month(Today),1))
End Select
Return FormatDateTime(GetStartDate,2)
End Function
The StartDate parameter is setup as a DateTime and the "Available Values" and the "Default Values" are set to use this custom code to preload the parameter. When only the "Default Values" is set and the "Available Values" is set to None, the Start & End Date parameters are set correctly using the "dd/MM/yyyy" but will not change when the Date Option is changed unless the report is refreshed.
When the "Available Values" and the "Default Values" are set to use this custom code, the Start & End Date parameters are set using the "dd/MM/yyyy HH:mm:ss" and will function propertly when the Date Option is changed.
My problems
- Eliminating the time section of the Start & End Date parameters.
- Setting the Start & End Date parameters to blank when the "Custom" option is selected.