Help with INSERT query

S

SirPoonga

I am making a custom import script to import data from a text file into
a table.

I do something like
sqlcmd = "INSERT INTO " & outTable & " " & _
"(" & record_names & ") " & _
"VALUES (" & outString & ")"
CurrentProject.Connection.Execute sqlcmd

I put a breakpoint on the execute command. When that line is run I get
Run-time error '-2147217900(80040e14)':
Syntax error in INSERT INTO statement.

ok, so in my immediate window I did a
print sqlcmd

I copy and pasetd the SQL cmd into the SQL view of the Query Builder.
The command ran fine.

So, why would a SQL statement run fine in the Query Builder but not in
code?
 
S

SirPoonga

Figured it out. If one of your record names happens to be the same
name as a datatype...
I put [] around the field names as they were being generated and that
solved it.
 

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