Insert Into DATE() does not work -gives wrong date

G

Guest

I found the following code in a previous post and I am trying to use this:

Private Sub MyProcedureName
Dim sSQL as string

sSQL = "INSERT INTO Dispositions([Date], [EventID], [Disposition]) " & _
"VALUES (" & DATE() & ", " & Me.EventID & ", 'Opened');"

CurrentDb.Execute sSQL

End Sub

however, the DATE() in the Values portion of the statement does not
work. Access 97 kicks out the brackets following DATE, therefor the date
inserted is incorrect.

Any ideas how one might correct the date?

Would there be a correct solution such as:

Dim InsertDate as string

InsertDate = DATE()


Cheers
 
R

Rick Brandt

NoSpam said:
I found the following code in a previous post and I am trying to use this:
Private Sub MyProcedureName
Dim sSQL as string

sSQL = "INSERT INTO Dispositions([Date], [EventID], [Disposition]) " & _
"VALUES (" & DATE() & ", " & Me.EventID & ", 'Opened');"

CurrentDb.Execute sSQL

End Sub

Dates need to be delimited with #.
sSQL = "INSERT INTO Dispositions([Date], [EventID], [Disposition]) " & _
"VALUES (#" & DATE() & "#, " & Me.EventID & ", 'Opened');"

CurrentDb.Execute sSQL
 
D

Douglas J. Steele

Rick Brandt said:
NoSpam said:
I found the following code in a previous post and I am trying to use this:
Private Sub MyProcedureName
Dim sSQL as string

sSQL = "INSERT INTO Dispositions([Date], [EventID], [Disposition]) " & _
"VALUES (" & DATE() & ", " & Me.EventID & ", 'Opened');"

CurrentDb.Execute sSQL

End Sub

Dates need to be delimited with #.
sSQL = "INSERT INTO Dispositions([Date], [EventID], [Disposition]) " & _
"VALUES (#" & DATE() & "#, " & Me.EventID & ", 'Opened');"

CurrentDb.Execute sSQL


Another option would be not to have the Date function outside of the quotes:

sSQL = "INSERT INTO Dispositions([Date], [EventID], [Disposition]) " & _
"VALUES (DATE(), " & Me.EventID & ", 'Opened');"
 

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