L
Lynndyhop
Hi there!
Wondering if I could get some help de-bugging....I have a form
(DateInputForm) that gets a start and end date and then on a cmd button 'OK'
there is the following code to filter dates for a report, based upon field
'ContactDate' in the report. It's designed to filter on dates in the
following way:
-Start date only - filter from start date on - PROBLEM - Filters everything
out.
-End date only - filter anything before end date - PROBLEM - Filters
everything out.
-No dates - Don't filter - PROBLEM - filters everything
-Both dates - Filter between - WORKS!
Here is the code - Any ideas? I think it may not recognize the values as
null, but not sure what to do or how to test.... (Many thanks!!)
Dim strReport As String 'Name of report to open.
Dim strField As String 'Name of your date field.
Dim strWhere As String 'Where condition for OpenReport.
Const conDateFormat = "\#dd\/mm\/yyyy\#"
strReport = "ContactsSummaryFilterReport"
strField = "ContactDate"
If IsNull(Me.StartDateInput) Then
If Not IsNull(Me.EndDateInput) Then 'End date, but no start.
strWhere = strField & " <= " & Format(Me.EndDateInput,
conDateFormat)
Else
DoCmd.OpenReport strReport, acViewPreview 'If no start or end
date.
End If
Else
If IsNull(Me.EndDateInput) Then 'Start date, but no End.
strWhere = strField & " >= " & Format(Me.StartDateInput,
conDateFormat)
Else 'Both start and end dates.
strWhere = strField & " Between " & Format(Me.StartDateInput,
conDateFormat) _
& " And " & Format(Me.EndDateInput, conDateFormat)
End If
End If
Debug.Print strWhere 'For debugging purposes only.
DoCmd.OpenReport strReport, acViewPreview, , strWhere
Wondering if I could get some help de-bugging....I have a form
(DateInputForm) that gets a start and end date and then on a cmd button 'OK'
there is the following code to filter dates for a report, based upon field
'ContactDate' in the report. It's designed to filter on dates in the
following way:
-Start date only - filter from start date on - PROBLEM - Filters everything
out.
-End date only - filter anything before end date - PROBLEM - Filters
everything out.
-No dates - Don't filter - PROBLEM - filters everything
-Both dates - Filter between - WORKS!
Here is the code - Any ideas? I think it may not recognize the values as
null, but not sure what to do or how to test.... (Many thanks!!)
Dim strReport As String 'Name of report to open.
Dim strField As String 'Name of your date field.
Dim strWhere As String 'Where condition for OpenReport.
Const conDateFormat = "\#dd\/mm\/yyyy\#"
strReport = "ContactsSummaryFilterReport"
strField = "ContactDate"
If IsNull(Me.StartDateInput) Then
If Not IsNull(Me.EndDateInput) Then 'End date, but no start.
strWhere = strField & " <= " & Format(Me.EndDateInput,
conDateFormat)
Else
DoCmd.OpenReport strReport, acViewPreview 'If no start or end
date.
End If
Else
If IsNull(Me.EndDateInput) Then 'Start date, but no End.
strWhere = strField & " >= " & Format(Me.StartDateInput,
conDateFormat)
Else 'Both start and end dates.
strWhere = strField & " Between " & Format(Me.StartDateInput,
conDateFormat) _
& " And " & Format(Me.EndDateInput, conDateFormat)
End If
End If
Debug.Print strWhere 'For debugging purposes only.
DoCmd.OpenReport strReport, acViewPreview, , strWhere