As a newbie in vba-sql, I am trying to populate a table using a for loop in vba and the Docmd.runsql to populate the table. The code works fine but then the values in the table are: 12/30/1899 for all the records. I used a message box to check and dt works fine. It gives me the date in the loop and moves to the next but in the table it only gives me one date: 12/30/1899.
Function dateTblUpdate()
DoCmd.SetWarnings False
DoCmd.RunSQL "DELETE FROM [date-table]"
Dim dt As Date
For dt = #1/1/2010# To DateSerial(Year(Now), Month(Now), Day(Now))
'MsgBox DateSerial(Year(Now), Month(Now), Day(Now))
'MsgBox dt
DoCmd.RunSQL "Insert into [date-table] (the_date) values(" & dt & ")"
Next
DoCmd.SetWarnings True
End Function
date-table current outcome
the_date
----------
12/30/1899
12/30/1899
12/30/1899
12/30/1899
12/30/1899
12/30/1899
But Expected outcome:
the_date
------------
01/01/2010
01/02/2010
01/03/2010
01/04/2010
My date column is of date type and I believe sql is thinking dt is not a date so it is not saving it and saving the default date.... Any ideas?