Hi again,
I have 2 combo boxes, one has the fields and the other has date options. So cbo1 has values like Closed Date, End Date, Start Date, Length and cbo2 has This Week, Next Week, 120 Days+, etc.
I have tried various formulas that have worked in other objects, but because this one has dates, nothing has worked. So now I am trying to nest it, but I keep getting invalid use of null!!!! There won't be many results with no date, so I always want to include the null fields when I filter.
Any thoughts on how to do that? I tried playing with OR IS NULL, but no luck.
I apologize if this is all sorts of ugly...
I have 2 combo boxes, one has the fields and the other has date options. So cbo1 has values like Closed Date, End Date, Start Date, Length and cbo2 has This Week, Next Week, 120 Days+, etc.
I have tried various formulas that have worked in other objects, but because this one has dates, nothing has worked. So now I am trying to nest it, but I keep getting invalid use of null!!!! There won't be many results with no date, so I always want to include the null fields when I filter.
Any thoughts on how to do that? I tried playing with OR IS NULL, but no luck.
I apologize if this is all sorts of ugly...
Code:
Private Sub cmdfilter_Click()
Dim strDate As Date
Dim strField As String
Select Case Me.cboReportField.Value
Case "Closed Date"
strField = "Closed Date"
Select Case Me.Filterby.Value
Case "This Month"
strDate = Year([Closed Date]) = Year(Now()) And Month([Closed Date]) = Month(Now()) & " "
Case "This Quarter"
strDate = Year([Closed Date]) = Year(Now()) And DatePart("q", [Closed Date]) = DatePart("q", Now())
Case "This Year"
strDate = Year([Closed Date]) = Year(Date)
End Select
Case "End Date"
strField = "End Date"
Select Case Me.Filterby.Value
Case "This Month"
strDate = Year([End Date]) = Year(Now()) And Month([End Date]) = Month(Now())
Case "This Quarter"
strDate = Year([End Date]) = Year(Now()) And DatePart("q", [End Date]) = DatePart("q", Now())
Case "This Year"
strDate = Year([End Date]) = Year(Date)
Case "This Week"
strDate = DatePart("ww", [End Date]) = DatePart("ww", Date) And Year([End Date]) = Year(Date)
Case "Next Week"
strDate = Year([End Date]) * 53 + DatePart("ww", [End Date]) = Year(Date) * 53 + DatePart("ww", Date) + 1
Case "Last Month"
strDate = Year([End Date]) * 12 + DatePart("m", [End Date]) = Year(Date) * 12 + DatePart("m", Date) - 1
End Select
Case "Start Date"
strField = "Start Date"
Select Case Me.Filterby.Value
Case "This Month"
strDate = Year([Start Date]) = Year(Now()) And Month([Start Date]) = Month(Now())
Case "This Quarter"
strDate = Year([Start Date]) = Year(Now()) And DatePart("q", [Start Date]) = DatePart("q", Now())
Case "This Year"
strDate = Year([Start Date]) = Year(Date)
Case "Last Month"
strDate = Year([Start Date]) * 12 + DatePart("m", [Start Date]) = Year(Date) * 12 + DatePart("m", Date) - 1
End Select
Case "Trial Length"
strField = "Trial Length"
Select Case Me.Filterby.Value
Case "120 Days+"
strDate = "[End Date] < [Start Date] + 120"
Case "30 Days+"
strDate = "[End Date] < [Start Date] + 30"
End Select
End Select
If Me.cboReportField.Value = strField Then
DoCmd.ApplyFilter , strDate
End If
End Sub