Michael Dean
asked on
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.InvoiceSentDa te) Between [Forms]![form1]![text63] And [Forms]![form1]![text65]) AND ((Customers.Company)='USAA INSURANCE COMPANY')) OR (((Customers.Company)="Sch wartz Law Firm, PC")) OR (((Customers.Company)="Gar an, Lucow, Miller, PC"));
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.InvoiceSentDa
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
but you probably don't need the DateValue referring to your form controls.
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.
WHERE DateValue(tblClaims.InvoiceSentDate) >= cdate([Forms]![form1]![text63])
AND DateValue(tblClaims.InvoiceSentDate) <= cdate([Forms]![form1]![text65])
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.
Updated. Please try . No need to put DATEVALUE around texts are they are dates only.
WHERE ((DATEVALUE(tblClaims.Invo iceSentDat e) Between [Forms]![form1]![text63] And [Forms]![form1]![text65]) AND ((Customers.Company)='USAA INSURANCE COMPANY')) OR (((Customers.Company)="Sch wartz Law Firm, PC")) OR (((Customers.Company)="Gar an, Lucow, Miller, PC"));
OR
WHERE ((DATEVALUE(tblClaims.Invo iceSentDat e) >= [Forms]![form1]![text63] And
DATEVALUE(tblClaims.Invoic eSentDate) <= [Forms]![form1]![text65]) AND ((Customers.Company)='USAA INSURANCE COMPANY')) OR (((Customers.Company)="Sch wartz Law Firm, PC")) OR (((Customers.Company)="Gar an, Lucow, Miller, PC"));
WHERE ((DATEVALUE(tblClaims.Invo
OR
WHERE ((DATEVALUE(tblClaims.Invo
DATEVALUE(tblClaims.Invoic
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.
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.
WHERE DateValue(tblClaims.Invoic
AND DateValue(tblClaims.Invoic