Connecting Tech Pros Worldwide Forums | Help | Site Map

SQL INSERT INTO PROBLEM

Guest
 
Posts: n/a
#1: Nov 13 '05
I have the following lines in a macro:
sql = "INSERT INTO IM (ITEM, DESC) VALUES (vitem, ndesc)"

DoCmd.RunSQL sql

Every time I execute the macro, I get a run time error saying there is a
syntax error in the INSERT INTO command. I have tried numerous variations
with the same result.

I would greatly appreciate anybody's help in pointing me in the right
direction.

John Cantlin



Douglas J. Steele
Guest
 
Posts: n/a
#2: Nov 13 '05

re: SQL INSERT INTO PROBLEM


Assuming vitem and ndesc are variables, they need to be outside of the
string so that you get their value in the SQL statement, not just their
name. For text fields, you need to enclose the value in quotes.

Assuming Item is a numeric field and Desc a text field, something like:

sql = "INSERT INTO IM (ITEM, [DESC]) VALUES (" & vitem & ", '" & ndesc &
"')"

BTW, I'd rename the second field. I believe that DESC is a reserved word,
and shouldn't be used for anything.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)



<jpcantlin@cox.net> wrote in message
news:cQnxd.60657$ka2.26515@fed1read04...[color=blue]
> I have the following lines in a macro:
> sql = "INSERT INTO IM (ITEM, DESC) VALUES (vitem, ndesc)"
>
> DoCmd.RunSQL sql
>
> Every time I execute the macro, I get a run time error saying there is a
> syntax error in the INSERT INTO command. I have tried numerous variations
> with the same result.
>
> I would greatly appreciate anybody's help in pointing me in the right
> direction.
>
> John Cantlin
>
>[/color]


Closed Thread


Similar Microsoft Access / VBA bytes