Dates in SQL query won't match

G

Gustaf

I'm importing data from Access into Excel. At one point, I need to import dates, and for some reason they don't match.

month = CDate(Cells(1, iCol))
....
Set rs = New ADODB.Recordset
rs.Open "SELECT * FROM Occupancy WHERE [Month] = " & month, cn, adOpenKeyset, adLockOptimistic

I have 3 records in Occupancy where Month is 2008-04-01. When the month variable is also 2008-04-01, I still get 0 on rs.RecordCount! The month is stored as a Date/Time (short date) in Access. I also tried

WHERE [Month] = " & Format(month, "yyyy-mm-dd")

Still no success.

Gustaf
 
G

Gustaf

Gustaf said:
I'm importing data from Access into Excel. At one point, I need to
import dates, and for some reason they don't match.

Found it. I need to write

WHERE [Month] = #" & month & "#"

Gustaf
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top