SQL Error

  • Thread starter Thread starter Charlie Brown
  • Start date Start date
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.
 
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().
 
Back
Top