I have constructed a query to select all dates between a date range which is inputted by the user. When the user selects the date before todays date, the current date or a day after the current date it brings back dates not within the date range.
Please see my examples below:
Before todays date returning incorrect dates in range:
Selecting date 3 days after current date query query perfectly:
Option Compare Database
Private Sub Command121_Click()
Dim strCriteria, task As String
strCriteria = "([PromisedDeliveryDate] >= #" & Me.DateFrom & "# And [PromisedDeliveryDate] <= #" & Me.DateTo & "#)"
task = "select * from SageOrderLine_Live where (" & strCriteria & ")"
DoCmd.ApplyFilter task
End Sub
EDIT: How would I add to query by the customeraccountnumber
as well? I have tried to add it on but it's bringing up an error:
DoCmd.ApplyFilter _
"select * from SageOrderLine_Live where " & _
"[PromisedDeliveryDate] >= " & Format(Me.DateFrom, "\#mm\/dd\/yyyy\#") & " and " & _
"[PromisedDeliveryDate] <= " & Format(Me.DateTo, "\#mm\/dd\/yyyy\#") & " and " & _
"[CustomerAccountNumber] = " & Me.CustomerAccount & ""
The "Enter parameter box" is appearing when selecting search: