I am trying to set up a form, in which the user can input specific date ranges to call data from a query. The form is set, and accepts the date inputs however it is not returning any data from the query. Here is the code I used to build the form:
[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 = "\#mm\/dd\/yyyy\#"
strReport = "qryDateRange1"
strField = "Date"
If IsNull(Me.txtStartDate) Then
If Not IsNull(Me.txtEndDate) Then 'End date, but no start.
strWhere = strField & " <= " & Format(Me.txtEndDate, conDateFormat)
End If
Else
If IsNull(Me.txtEndDate) Then 'Start date, but no End.
strWhere = strField & " >= " & Format(Me.txtStartDate, conDateFormat)
Else 'Both start and end dates.
strWhere = strField & " Between " & Format(Me.txtStartDate, conDateFormat) _
& " And " & Format(Me.txtEndDate, conDateFormat)
End If
End If
' Debug.Print strWhere 'For debugging purposes only.
DoCmd.OpenReport strReport, acViewPreview, , strWhere]
"2 txt boxes in header, code below"
[=Forms.frmWhatDates.txtStartDate
=Forms.frmWhatDates.txtEndDate]
If I leave the "Debug.Print" statement I get an error telling me the "qryDateRange1" is misspellled or does not exist. If i take the statement out, nothing happens.
I appreciate any suggestions, thank you in advance for any help!!!
[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 = "\#mm\/dd\/yyyy\#"
strReport = "qryDateRange1"
strField = "Date"
If IsNull(Me.txtStartDate) Then
If Not IsNull(Me.txtEndDate) Then 'End date, but no start.
strWhere = strField & " <= " & Format(Me.txtEndDate, conDateFormat)
End If
Else
If IsNull(Me.txtEndDate) Then 'Start date, but no End.
strWhere = strField & " >= " & Format(Me.txtStartDate, conDateFormat)
Else 'Both start and end dates.
strWhere = strField & " Between " & Format(Me.txtStartDate, conDateFormat) _
& " And " & Format(Me.txtEndDate, conDateFormat)
End If
End If
' Debug.Print strWhere 'For debugging purposes only.
DoCmd.OpenReport strReport, acViewPreview, , strWhere]
"2 txt boxes in header, code below"
[=Forms.frmWhatDates.txtStartDate
=Forms.frmWhatDates.txtEndDate]
If I leave the "Debug.Print" statement I get an error telling me the "qryDateRange1" is misspellled or does not exist. If i take the statement out, nothing happens.
I appreciate any suggestions, thank you in advance for any help!!!