View Full Version : Stumped on "INSERT INTO..." command


Mendel
12-12-2001, 07:21 AM
My code is comparing 2 tables, a Master Data table and a Raw Data table to find any discrepancies between them. Then I create an output table "TableDiscrepancies" to display the discrepancies.

In the beginning of my code I delete a table: dbs.TableDefs.Delete "TableDiscrepancies"
and then re-add it: dbs.Execut("CREATE TABLE TableDiscrepancies(Field1 TEXT, Field2 TEXT);")

and this works fine. Then I run the body of the code that does the checks between the tables. If there is a discrepancy then I set variables Field1 as the key and Field2 as the Field with the Discrepancy.

Now I want to output this to "TableDiscrepancies" and I've written the code like this:

dbs.Execute("INSERT INTO TableDiscrepancies(Field1)" & "The discrepancy is " & Field2" http://www.access-programmers.co.uk/ubb/wink.gif

This obviously is incorrect because I'm getting a Syntax error and it doesn't work and I'm having trouble finding how to write it correctly and make it work. Can anyone show me the err of my ways? Thanks for any assistance.

[This message has been edited by Mendel (edited 12-12-2001).]

boblarson
12-13-2001, 06:00 PM
I could be off here, but I think your quotation marks are off the mark.

Instead of
dbs.Execute("INSERT INTO TableDiscrepancies(Field1)" & "The discrepancy is " & Field2"

have you tried:
dbs.Execute("INSERT INTO TableDiscrepancies(Field1) & 'The discrepancy is ' & Field2"

Mendel
12-19-2001, 03:00 PM
Thanks for the advice. I changed it to read:

dbs.Execute("INSERT INTO Table(Field1)" & "VALUES("' & Field1 & '");")

Works great now! http://www.access-programmers.co.uk/ubb/smile.gif