Query returns more records standalone than in VBA

EM 271 Reputation points
2021-09-29T20:56:58.367+00:00

I've got a table in sql server with a date column formatted as datetime. The date is added to this table either manually or thru an automated import process. If manually, just the date gets written to the sql table. If automated, the date and time get written. For example, if manually added, 2021-09-29 00:00:00.000 gets written to the database. Otherwise 2021-09-29 15:23:38.000 would be written.

In Access, this data is displayed as such:
136339-capture.png

If I run this query in the query designer, I get the rows I expect:
SELECT tblOrder.OrderID, tblOrder.ReceivedDate
FROM tblOrder
WHERE (((tblOrder.ReceivedDate)>=#9/29/2021# And (tblOrder.ReceivedDate)<=#9/29/2021 23:59:59#))
ORDER BY tblOrder.ReceivedDate DESC;

If I code this query in a VBA module (which is in the Report_Open module in an Access report) only those rows with 9/29/2021 00:00:000 are returned. The rest is ignored.

So, I modified the query in VBA like so:

SELECT tblOrder.OrderID, tblOrder.ReceivedDate  
FROM tblOrder  
WHERE (((FormatDateTime(tblOrder.ReceivedDate, 0)>=#9/29/2021# And (FormatDateTime(tblOrder.ReceivedDate, 0))<=#9/29/2021 23:59:59#))  
ORDER BY tblOrder.ReceivedDate DESC;  

But it still ignores the rows with the format mm/dd/yyyy hh:mm:ss.

The query returns the desired rows only when run in the query designer.

How do I get the query in VBA to match the query in the designer?

Thanks.

Access Development
Access Development
Access: A family of Microsoft relational database management systems designed for ease of use.Development: The process of researching, productizing, and refining new or existing technologies.
817 questions
0 comments No comments
{count} votes

12 answers

Sort by: Most helpful
  1. EM 271 Reputation points
    2021-10-05T21:14:10.27+00:00

    Yes, I get the correct records if I run that in query designer.

    Yeah, I'm going to try updating table data with missing time. Or I may just redevelop the report in something other than Access.

    Thanks for your help.

    0 comments No comments

  2. DBG 2,301 Reputation points
    2021-10-05T21:15:41.053+00:00

    Yeah, maybe like Crystal Reports. Good luck!

    0 comments No comments