Private Sub cboRangeDate_AfterUpdate()
'Set date ranges in hidden start & end date controls
Select Case Me.cboRangeDate.Value
Case Is = "Today"
txtHiddenStartDate = Date
txtHiddenEndDate = Date
Case Is = "Custom dates"
txtFromDate.Visible = yes
txtToDate.Visible = yes
txtHiddenStartDate = txtFromDate
txtHiddenEndDate = txtToDate
Case Is = "All to date"
txtHiddenStartDate = #1/1/100#
txtHiddenEndDate = Date
Case Is = "All dates"
txtHiddenStartDate = #1/1/100#
txtHiddenEndDate = #1/1/3000#
Case Is = "Current month"
txtHiddenStartDate = Format(Now(), "M") & "/" & "1" & "/" & Format(Now(), "yyyy")
txtHiddenEndDate = DateAdd("M", 1, Now) 'next month
txtHiddenEndDate = Format(txtHiddenEndDate, "M") & "/" & "1" & "/" & Format(Now(), "yyyy") '1st of next month
txtHiddenEndDate = DateAdd("d", -1, txtHiddenEndDate) 'last day of current month
Case Is = "Current year"
txtHiddenStartDate = "1" & "/" & "1" & "/" & Format(Now(), "yyyy")
txtHiddenEndDate = DateAdd("yyyy", 1, Now) 'next year
txtHiddenEndDate = "1" & "/" & "1" & "/" & Format(txtHiddenEndDate, "yyyy") '1st day of next year
txtHiddenEndDate = DateAdd("d", -1, txtHiddenEndDate) 'last day of current year
Case Is = "Month to date"
txtHiddenStartDate = Format(Now(), "M") & "/" & "1" & "/" & Format(Now(), "yyyy")
txtHiddenEndDate = Now()
Case Is = "Year to date"
txtHiddenStartDate = "1" & "/" & "1" & "/" & Format(Now(), "yyyy")
txtHiddenEndDate = Now()
Case Is = "Previous month"
txtHiddenStartDate = Format(DateAdd("m", -1, Date), "m") & "/" & "1" & "/" & Format(Now(), "yyyy")
txtHiddenEndDate = Format(Now(), "M") & "/" & "1" & "/" & Format(Now(), "yyyy") '1st of current month
txtHiddenEndDate = DateAdd("d", -1, txtHiddenEndDate) 'previous month last day
Case Is = "Previous year"
txtHiddenStartDate = "1" & "/" & "1" & "/" & Format(DateAdd("yyyy", -1, Now), "yyyy")
txtHiddenEndDate = "1" & "/" & "1" & "/" & Format(txtHiddenEndDate, "yyyy") '1st day of current year
txtHiddenEndDate = DateAdd("d", -1, txtHiddenEndDate) 'last day of last year
Case Is = "Last 30 days"
txtHiddenStartDate = DateAdd("d", -31, Date)
txtHiddenEndDate = Now()
Case Is = "Last 3 months"
txtHiddenStartDate = DateAdd("d", -91, Date)
txtHiddenEndDate = Now()
Case Is = "Last 6 Months"
txtHiddenStartDate = DateAdd("m", -7, Date)
txtHiddenEndDate = Now()
Case Is = "Last 12 months"
txtHiddenStartDate = DateAdd("m", -13, Date)
txtHiddenEndDate = Now()
Case Is = "Next 30 days"
txtHiddenStartDate = Now()
txtHiddenEndDate = DateAdd("d", 31, Date)
Case Is = "Next 3 months"
txtHiddenStartDate = Now()
txtHiddenEndDate = DateAdd("d", 91, Date)
Case Is = "Next 6 Months"
txtHiddenStartDate = Now()
txtHiddenEndDate = DateAdd("m", 7, Date)
Case Is = "Next 12 months"
txtHiddenStartDate = Now()
txtHiddenEndDate = DateAdd("m", 13, Date)
Refresh
End Select
For completness the query criteria is
Between [Forms]![F_FindReplace]![txtHiddenStartDate] And [Forms]![F_FindReplace]![txtHiddenEndDate][code/]
It's exciting when you can get things to work. Thanks for your help.
Two minor issues remain that I could use some direction on:
1. Null dates are not addressed. Since the query criteria is a range how on earth can one address nulls?
2. THe All dates and All to date ranges were artificially force using 1/1/100 as the earliest date and 1/1/3000 as the latest future date. Seems like something less arbitrary would be better?