Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA / Access97 SQL date issue 1

Status
Not open for further replies.

MyNeckHurts

Programmer
Apr 5, 2002
34
US
I'm running a function that should pass dates to a table. In the following example the variables debug as MyDate1 = #12/1/2004# and MyDate2 = #12/31/2004#. When they load into the table they both load as 12/30/1899. Does anyone know what's going on here?

Public Function FetchDate()
' Function to be used to pass dates to a table for a pass thru query to call the first and
' last day of the prior month.

Dim MyDate1
Dim Mydate2

DoCmd.SetWarnings False

DoCmd.OpenQuery "Delete_Dates"

MyDate1 = Now() - Day(Now()) - (Day(Now() - Day(Now())) - 1)

MyDate1 = Format$([MyDate1], "Short Date")

Mydate2 = Now() - Day(Now())

Mydate2 = Format$([Mydate2], "Short Date")

DoCmd.RunSQL "INSERT INTO FetchDateTable (FetchStartDate, FetchEndDate) VALUES (" & MyDate1 & "," & Mydate2 & ");"

End Function
 
And this ?
DoCmd.RunSQL "INSERT INTO FetchDateTable (FetchStartDate, FetchEndDate) VALUES (#" & MyDate1 & "#,#" & Mydate2 & "#);"

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top