INSERT INTO syntax error

T

Tom

The function below gives me the error:

"Syntax error in INSERT INTO statment. (3134)".

Does anyone know how to modify the INSERT statement?

Also, the DATE format should be simply in "MM-DD-YY"
format?

Thanks in advance,
Tom

&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&


Private Sub Location_AfterUpdate()
On Error GoTo Err_Location_AfterUpdate

strSQL = "INSERT INTO History" & _
"VALUES ( " & _
Format$(Now(), "\#yyyy\-mm\-dd hh\:nn\#")
& ", " & _
"""" & Me!Location.Value & """)"


MsgBox strSQL, , "Location history table will be
updated!"

CurrentDb().Execute strSQL, dbFailOnError

End_Location_AfterUpdate:
Exit Sub

Err_Location_AfterUpdate:
MsgBox Err.Description & " (" & Err.Number & ")", _
vbOKOnly + vbCritical
Resume End_Location_AfterUpdate

End Sub
 
S

Scott McDaniel

'strSQL = "INSERT INTO History (NameofField1, NameOfField2) VALUES(#" &
Format(Now(), 'mm-dd-yy') & "#, ' " & Me!Location.Value & " ' )"

This assumes that your second value is a string ... Note that you may not
need to add the NameofField1 and NameOfField2, but I've always included them
in my string since it makes the INSERT easier to read. Note also that I have
purposely included extra spaces around the single quotes ( ' ) to make sure
they show up. You'll have to remove those spaces for this to work.
 

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