dbTalk Databases Forums  

SQL INSERT INTO problem

comp.database.ms-access comp.database.ms-access


Discuss SQL INSERT INTO problem in the comp.database.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
 
Posts: n/a

Default SQL INSERT INTO problem - 12-19-2004 , 01:38 PM






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



Reply With Quote
  #2  
Old   
Ken Snell
 
Posts: n/a

Default Re: SQL INSERT INTO problem - 12-20-2004 , 08:35 AM






What are vitem and ndesc? Are they variables in your code? If yes,
concatenate their values into the string:

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


--

Ken Snell
<MS ACCESS MVP>


<jpcantlin (AT) cox (DOT) net> wrote

Quote:
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





Reply With Quote
  #3  
Old   
Joe Gleason
 
Posts: n/a

Default Re: SQL INSERT INTO problem - 12-20-2004 , 09:09 AM



For troubleshooting SQL errors like this, put a "debug.print sql"
statement in your code, right after you've completed building your sql
string. Put in a breakpoint after that. Now you can lift the sql
statement from the immediate window and examine it for syntax errors.
You can also paste it inot SQL Query Analyzer and execute the statement.

Ken Snell wrote:
Quote:
What are vitem and ndesc? Are they variables in your code? If yes,
concatenate their values into the string:

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



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.