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!

Syntax Error in Insert Into Statement 1

Status
Not open for further replies.

DYM03

Technical User
Mar 6, 2003
28
US
I keep getting a syntax error on the last line of this Insert statement. I have tried a number of things and nothing is working. Please help me. I am working in Access and trying to enter this data into a table in the database. Do I need to open the table or define the database or something?

DoCmd.RunSQL "INSERT INTO Trans Log " _
& "(USER, TIME, TRANS) VALUES " _
& "('1', '1', '1');"
 
Have you tried it in the Access query window? Are all of the values defined as text?
 
You have a couple of problems here.

1. If the table name contains spaces as indicated in your post (and not just a typo), then you need to place the name in square brackets so the statement can parse correctly:
[blue]
Code:
   ... INSERT INTO [Trans Log] ...
[/color]


2. "TIME" is a reserved word in Access. "Good" design would suggest not to use reserved words as field names, however if you insist, the solution is the same: use square brackets:
[blue]
Code:
    ... USER, [TIME], TRANS ...
[/color]

 
Thanks Zathras. I needed to enter the brackets around the table name. I didn't even think of that.

Thanks jcrater. I would rather used code for this step because I will probably be making a number of changes and testing. I tried the query but it didn't really do what I needed it to.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top