kaushikpasi
kaushikpasi

Reputation: 21

Date variable in vba using sql query

I have a query in VB6:

"select plate_no from INFO where date_time between #07-10-2012 01:13:17# and #10/10/2012 11:30:25#" 

My Access database table has the column with datatype Data/Time in general format.

How do I modify the query above to use variables like:

Public t1 As Date 
Public t2 As Date 

Upvotes: 2

Views: 5870

Answers (1)

Mark Stevens
Mark Stevens

Reputation: 2366

I'm doing it from memory, may have to tweak it to compile:

Public t1 as Date
Public t2 as Date

t1 = #10/07/2012 01:13:17# '7th of October 2012
t2 = #10/10/2012 11:30:25# '10th of October 2012

sql = "select plate_no from INFO where date_time between #" + Format(t1, "YYYY-MM-DD HH:MM:SS") + "# and #" + Format(t2, "YYYY-MM-DD HH:MM:SS") + "#"

Upvotes: 4

Related Questions