Help with INSERT query

  • Thread starter Thread starter SirPoonga
  • Start date Start date
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?
 
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.
 
Back
Top