I am trying to filter a report by a date range using the code below. I know the filter string is supposed to be something like:
I just cant get it. I have a text box for the StartDate and one for the EndDate.
Can someone show me what my code should look like? Thanks in advance.
Code:
([StartDate] >= #strfilter#) AND ([EndDate] <= #strfilter#)
I just cant get it. I have a text box for the StartDate and one for the EndDate.
Can someone show me what my code should look like? Thanks in advance.
Code:
Private Sub cmdFilterByDate_Click()
Dim strDoc As String
strDoc = "SummaryReport"
'Set Date Range Filter
If Nz(Me.txtStartDate, vbNullString) <> vbNullString And Nz(Me.txtEndDate, vbNullString) <> vbNullString Then
If Me.txtStartDate > Me.txtEndDate Then
MsgBox "Start Date Cannot Be Greater Than End Date", vbInformation
Exit Sub
End If
End If
If Nz(Me.txtStartDate, vbNullString) <> vbNullString Then
strFilter = strFilter & " AND [StartDate] >= #" & Me.txtStartDate & "#"
End If
If Nz(Me.txtEndDate, vbNullString) <> vbNullString Then
strFilter = strFilter & " AND [ProjectedEndDate] <= #" & Me.txtEndDate & "#"
End If
DoCmd.OpenReport strDoc, acViewPreview, , strFilter