Sub ReportFilter()
'On Error Resume Next 'Remove this until things are working.
'It is usually (not always) a bad idea to have this in your code.
'Much better is to add some error trapping code and handle any errors
Dim strWhere As String 'The criteria string.
Dim lngLen As Long 'Length of the criteria string to append to.
' Dim strDateField As String 'Unused variable
' Dim lngView As Long 'Unused variable
Const conJetDate = "#mm/dd/yyyy#" 'The format expected for dates in a JET query string.
strDateField = "[TODATE]"
'I prefer to add " AND " to the beginning and eliminate all unneeded parentheses
If Not IsNull(Me.LocationSel) Then
strWhere = strWhere & " AND [Location] Like ""*" & Me. Location.Column(0) & "*"" "
End If
If Not IsNull(Me.IteamSel) Then
strWhere = strWhere & " AND [Iteam] Like ""*" & Me.IteamSel.Column(0) & "*"" "
End If
If IsDate(Me.StartDSel) Then
strWhere = strWhere & " AND [TODATE] >= " & Format(Me.StartDSel, conJetDate)
End If
If IsDate(Me.EndDSel) Then
strWhere = strWhere & " AND [TODATE] < " & Format(Me.EndDSel + 1, conJetDate)
End If
lngLen = Len(strWhere)
If lngLen < 5 Then 'Nah: there was nothing in the string.
MsgBox "No criteria", vbInformation, "Nothing to do."
Else 'there is something there, so remove the " AND " at the start of the string
strWhere = Mid(strWhere, 6)
'For debugging, remove the leading quote on the next line. Prints to Immediate Window (Ctrl+G).
'Debug.Print strWhere
'Finally, apply the string as the form's Filter.
Me.Filter = strWhere
Me.FilterOn = True
End If
End Sub
John Spencer Access MVP 2002-2005, 2007-2010 The Hilltop Institute University of Maryland Baltimore County