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"));
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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"));

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Dale FyeOwner, Dev-Soln LLCCommented:
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])
Dale FyeOwner, Dev-Soln LLCCommented:
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.
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"));


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"));
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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.