E
E
Eugene2016-06-11 11:29:12
Visual Basic
Eugene, 2016-06-11 11:29:12

How to correctly compose a query with a date in vba access?

There is Access 2013, it has a sold_test table imported from Excel. It has a date field with a date like 25/10/15, that is, dd/mm/yy. I'm trying to select records between January 2, 2015 and January 3, 2015:

Set rsSold = .OpenRecordset("SELECT * FROM sold_test WHERE date BETWEEN #01/02/2015# AND #01/03/2015#")

To begin with, at least like this, even without variables, I just specify the dates in the text of the request. I put the month first, because I read that it is customary in the USA and you must also do it in the office, otherwise the month and day will still change places. I tried the first day, and instead of the year, just set 15, the result is the same - records from 02/02/15 to 02/06/16 are issued. I also tried a query like this:
Set rsSold = .OpenRecordset("SELECT * FROM sold_test WHERE date > '02/01/15' AND date < '03/01/15'")

In the hope that he will compare them at least like regular strings.
In short, I'm shocked by this system. Never would have thought such a simple thing could be so complicated. Oh,
does anyone know how to write a query properly?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question