append query syntax error

mafhobb

Registered User.
Local time
Today, 17:15
Joined
Feb 28, 2006
Messages
1,249
Syntax error in this append query. What is it?

Code:
        Dim DataToAdd As String
        DataToAdd = "INSERT INTO Address " & _
        "customerId, addressNr, addressType, firstname, lastname, companyName, postalcode, country, workphone, email, notes, streetaddress, city, contactTypeId " & _
        "SELECT customerId, addressNr, addressType, firstname, lastname, companyName, postalcode, country, workphone, email, notes, streetaddress, city, contactTypeId " & _
        "FROM Customer WHERE ((Customer.function)=ADD);"
        Debug.Print DataToAdd
        CurrentDb.Execute DataToAdd, dbFailOnError

I am trying to append data from the query into the table where the value on function field in the query is equal to the word ADD

mafhobb
 
I am just trying to write in code this SQL query
Code:
INSERT INTO Address ( customerId, addressNr, addressType, firstname, lastname, companyName, postalcode, country, workphone, email, notes, streetaddress, city, contactTypeId )
SELECT Customer.customerId, Customer.addressNr, Customer.addressType, Customer.firstname, Customer.lastname, Customer.companyName, Customer.postalcode, Customer.country, Customer.workphone, Customer.email, Customer.notes, Customer.streetaddress, Customer.city, Customer.contactTypeId
FROM Customer
WHERE (((Customer.function)="INSERT"));

Which works just fine
 
There should be 14 fields on each statement. Is there something written wrong?
 
Isn't the syntax supposed to be
Code:
INSERT INTO tablename (field1, field2 etc)
VALUES (Value1, value2 etc)
WHERE criteria goes here
?
 
This works:
Code:
        CurrentDb.Execute "INSERT INTO Address ( customerId, addressNr, addressType, firstname, lastname, companyName, postalcode, country, workphone, email, notes, streetaddress, city, contactTypeId )" & _
        "SELECT Customer.customerId, Customer.addressNr, Customer.addressType, Customer.firstname, Customer.lastname, Customer.companyName, Customer.postalcode, Customer.country, Customer.workphone, Customer.email, Customer.notes, Customer.streetaddress, Customer.city, Customer.contactTypeId " & _
        "FROM Customer " & _
        "WHERE (Customer.function='ADD');"
 

Users who are viewing this thread

Back
Top Bottom