Click to See Complete Forum and Search --> : Sort By Date


aussiecyclone
April 18th, 2001, 05:26 PM
Hi,

I have an access DB with a field (MailDateSent), I want to sort between 2 dates, my code below is not working.

Any help appreciated.

Regards,

Alan.

Date1 = txtDate1.Text
Date2 = txtDate2.Text

'SQL = "SELECT * FROM Customers WHERE (MailDateSent) >= Date1 and (MailDateSent) <= Date2 ORDER bY CompanyName"

Set Customers = DB.OpenRecordset(SQL, dbOpenDynaset)

forty7
April 18th, 2001, 06:05 PM
I'm using SQL-Server so this may not be the right syntax for you, but I always have to put single quotes around dates.

SQL = "SELECT * FROM Customers WHERE (MailDateSent) >= '" & Date1 & "' and (MailDateSent) <= '" & Date2 & "' ORDER bY CompanyName"


thanx/good luck,
adam

d.paulson
April 18th, 2001, 10:12 PM
In access you use the pound sign.

SQL = "SELECT * FROM Customers WHERE (MailDateSent) >= #" & Date1 & "# and (MailDateSent) <= #" & Date2 & "# ORDER bY CompanyName"

David Paulson