How to retrieve date between two dates.

I have a query below, when the user enters on form1

10/1/2017       [text63] which is the earliest date
10/31/2017     [text65] which is the latest date

The results do not include 10/31 they only show up to 10/30.

What is the syntax to be used to include all rows that are from one to to and including another date?




WHERE (((tblClaims.InvoiceSentDate) Between [Forms]![form1]![text63] And [Forms]![form1]![text65]) AND ((Customers.Company)='USAA INSURANCE COMPANY')) OR (((Customers.Company)="Schwartz Law Firm, PC")) OR (((Customers.Company)="Garan, Lucow, Miller, PC"));
seamus9909Asked:
Who is Participating?
 
Pawan KumarDatabase ExpertCommented:
Please try this-

WHERE (((tblClaims.InvoiceSentDate) >= [Forms]![form1]![text63] And
(tblClaims.InvoiceSentDate) <= [Forms]![form1]![text65]) AND ((Customers.Company)='USAA INSURANCE COMPANY')) OR (((Customers.Company)="Schwartz Law Firm, PC")) OR (((Customers.Company)="Garan, Lucow, Miller, PC"));
0
 
Dale FyeCommented:
Chances are that your [SentDate] field includes a time component.  I generally use:

WHERE DateValue(tblClaims.InvoiceSentDate) >= DateValue([Forms]![form1]![text63])
AND DateValue(tblClaims.InvoiceSentDate) <= DateValue([Forms]![form1]![text65])
0
 
Dale FyeCommented:
but you probably don't need the DateValue referring to your form controls.
WHERE DateValue(tblClaims.InvoiceSentDate) >= cdate([Forms]![form1]![text63])
AND DateValue(tblClaims.InvoiceSentDate) <= cdate([Forms]![form1]![text65]) 

Open in new window

This assumes you have other code that would require that text63 and text65 contain values.  Otherwise, you might want to use the NZ() function to force dates into those criteria.

BTW.  I strongly recommend a control naming convention txt_FromDate, txt_ThruDate instead of accepting the default control names that Access assigns to controls on your form.  It is much easier to write code and debug it when the control names have meaning.
0
 
Pawan KumarDatabase ExpertCommented:
Updated. Please try . No need to put DATEVALUE around texts are they are dates only.

WHERE ((DATEVALUE(tblClaims.InvoiceSentDate) Between [Forms]![form1]![text63] And [Forms]![form1]![text65]) AND ((Customers.Company)='USAA INSURANCE COMPANY')) OR (((Customers.Company)="Schwartz Law Firm, PC")) OR (((Customers.Company)="Garan, Lucow, Miller, PC"));

OR

WHERE ((DATEVALUE(tblClaims.InvoiceSentDate) >= [Forms]![form1]![text63] And
DATEVALUE(tblClaims.InvoiceSentDate) <= [Forms]![form1]![text65]) AND ((Customers.Company)='USAA INSURANCE COMPANY')) OR (((Customers.Company)="Schwartz Law Firm, PC")) OR (((Customers.Company)="Garan, Lucow, Miller, PC"));
0
 
PatHartmanCommented:
Another solution, which avoids the use of VBA functions in the  WHERE clause which can adversely affect performance:

WHERE tblClaims.InvoiceSentDate >= [Forms]![form1]![text63]
AND tblClaims.InvoiceSentDate < [Forms]![form1]![text65] +1

PS - best practice is to actually name controls and forms with meaningful names.  You aren't going to know next week what text65 is let alone next year.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.