I have a form with several boxes in that a user selects data to filter a report, so what ever the user has in any or all of these boxes there is code that builds this info as a filter string. The code which was obtained from this site (but I cannot find exactly where or by whom) is like this
rivate Sub Command28_Click()
Dim strSQL As String, intCounter As Integer
'Build SQL String
For intCounter = 1 To 4
If Me("Filter" & intCounter) <> "" Then
strSQL = strSQL & "[" & Me("Filter" & intCounter).Tag & "] " & " = " & Chr(34) & Me("Filter" & intCounter) & Chr(34) & " And "
End If
Next
If strSQL <> "" Then
'Strip Last " And "
strSQL = Left(strSQL, (Len(strSQL) - 5))
'Set the Filter property
Debug.Print strSQL
Reports![ExpenseReport].Filter = strSQL
Reports![ExpenseReport].FilterOn = True
End If
End Sub
This works perfectly but what I have now been requested to do is include in the filter a 'from' and 'to' date, but I am totally lost as to how to change/add to this existing code.
Any help would be very much appreciated
Regards
Smalty
rivate Sub Command28_Click()
Dim strSQL As String, intCounter As Integer
'Build SQL String
For intCounter = 1 To 4
If Me("Filter" & intCounter) <> "" Then
strSQL = strSQL & "[" & Me("Filter" & intCounter).Tag & "] " & " = " & Chr(34) & Me("Filter" & intCounter) & Chr(34) & " And "
End If
Next
If strSQL <> "" Then
'Strip Last " And "
strSQL = Left(strSQL, (Len(strSQL) - 5))
'Set the Filter property
Debug.Print strSQL
Reports![ExpenseReport].Filter = strSQL
Reports![ExpenseReport].FilterOn = True
End If
End Sub
This works perfectly but what I have now been requested to do is include in the filter a 'from' and 'to' date, but I am totally lost as to how to change/add to this existing code.
Any help would be very much appreciated
Regards
Smalty