BrianBeck
asked on
"Syntax error in INSERT INTO statement" error (VB6/ Jet)
Dear Gurus
I receive a "syntax error in INSERT INTO statement" error when executing the following statement, and would be grateful of your assistance with the correction. I believe that the required text delimiters are in place.
SQLStr1 = "INSERT INTO " & tbl & " IN '" & txt_Output_Db & _
"' SELECT FROM '" & txt_db1 & "' WHERE POSTCODE = '" & pc & "'"
DbsConnection1.Execute SQLStr1
Thanks in advance
I receive a "syntax error in INSERT INTO statement" error when executing the following statement, and would be grateful of your assistance with the correction. I believe that the required text delimiters are in place.
SQLStr1 = "INSERT INTO " & tbl & " IN '" & txt_Output_Db & _
"' SELECT FROM '" & txt_db1 & "' WHERE POSTCODE = '" & pc & "'"
DbsConnection1.Execute SQLStr1
Thanks in advance
ASKER
Hi dqmq
Thank you for your suggestions. I've firstly replaced my SQL string with your edition. I've also ensured that the table structure of the output database is exactly the same as the source database (e.g. using Access's 'paste as structure only' command).
However, after the above, I still get the INSERT INTO syntax error. To assist, below is the SQL string generated from the code:
INSERT INTO DB_ALL IN D:\pc_test_struct.mdb SELECT FROM D:\pc_test.mdb WHERE POSTCODE = '2059
Can you help please?
Thank you for your suggestions. I've firstly replaced my SQL string with your edition. I've also ensured that the table structure of the output database is exactly the same as the source database (e.g. using Access's 'paste as structure only' command).
However, after the above, I still get the INSERT INTO syntax error. To assist, below is the SQL string generated from the code:
INSERT INTO DB_ALL IN D:\pc_test_struct.mdb SELECT FROM D:\pc_test.mdb WHERE POSTCODE = '2059
Can you help please?
ASKER
fyi, the SQL string includes a trailing apostrophe
ASKER
Hi dqmq
I've found a Microsoft article regarding reserved words:
http://support.microsoft.com/kb/248738/
I've checked the column names in the Access tables and am very sure that none are reserved.
By the way, given the importance of correct SQL syntax, and that SQL is used so frequently in software today, does Microsoft have a web site that allows me to upload an SQL string and fetch a detailed answer as to why syntax is incorrect?
I've found a Microsoft article regarding reserved words:
http://support.microsoft.com/kb/248738/
I've checked the column names in the Access tables and am very sure that none are reserved.
By the way, given the importance of correct SQL syntax, and that SQL is used so frequently in software today, does Microsoft have a web site that allows me to upload an SQL string and fetch a detailed answer as to why syntax is incorrect?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi harfang - yes, the table names are exactly the same in both databases, and both tables have exactly the same structure. You SQL string worked perfectly, thank you.
SQLStr1 = "INSERT INTO " & tbl & " IN " & txt_Output_Db & _
" SELECT * FROM " & txt_db1 & " WHERE POSTCODE = '" & pc & "'"
Note that I have also removed what appear to be extraneous quote marks.