SQL Error

C

Charlie Brown

Access 2003:
I am trying create a record of user login with a simple INSERT INTO to a
separate table which logs user name and date & time. This is executed when
they click "OK" on an existing login form. The form coding is already working
to allow them into the database, I am just adding this code to capture a
traffic record.

Here is the SQL statement I am using;

SQL = "INSERT INTO tblLog (User, LastLogon) VALUES(" & strUser & ", " &
Now() & ")"
DoCmd.RunSQL SQL

When the SQL is executed I get a "Syntax error (missing operator) in query
expression 'Charlie Brown'". It does the same thing for the date and time if
I remove the "User" portion of the code.

So much for being something simple for me. Any help will be appreciated.
 
G

George Nicholson

Try:
SQL = "INSERT INTO tblLog (User, LastLogon) VALUES('" & strUser & "', #" &
Now() & "#)"
DoCmd.RunSQL SQL

Note the addition of single quotes around strUser and date Delimiters (#)
around Now().
 
C

Charlie Brown

Great. That did the trick.
I knew it was probably something simple. Many thanks!!
 

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