Problem with date query. Help appreciated.

Holchr

New member
Joined
Apr 12, 2010
Messages
1
Programming Experience
Beginner
I am getting 'Syntax error in date in query expression 'Datum >= #1.4.2010.# and Datum <= #12.4.2010.'.

Datum is my date field in my database. I'm supposed to get all entries in the database where Datum (date) is between date selected on DateTimePicker1 and DateTimePicker2.

I have set date field format in access to Short Date, and also set Format property of datetimepickers to Short Date
Even tried using custom formats in both database and datetimepicker

I'm using MSAccess (Accdb) database

Query looks like this
"SELECT [Redni Broj], Vozilo, Prikolica, Vozač, [Kupac/dobavljač], Roba, [Mjesto isporuke], [Broj naloga], [Tara (kg)], [Netto (kg)], [Brutto (kg)], Datum, Vrijeme FROM Odvage WHERE Datum >= #" & Form1.DateTimePicker1.Value & "# and Datum <= #" & Form1.DateTimePicker2.Value & "# "

I can't get it to work!!!
 
Don't use string concatenation to build SQL statements. It's too prone to creating syntax errors and its a security risk. Use parameters to insert values into your SQL code. Follow the relevant blog link in my signature.
 
Back
Top