Code for RunSQL append query to select only some fields in a table

G

Guest

A2K3 database is installed in runtime.
The database imports a table from another database and then runs a query on
the imported table to append the data to an exisiting table.
(This is the first time I have used the Open File Dialog using code from the
Access Web and I am amazed that I could make that part of it work.)

I am using the following code:

'Run append query from temp table to table TrackRecords

DoCmd.RunSQL "INSERT INTO " & strExistingTableName & _
" SELECT tbl_Temp.* " & _
" FROM tbl_Temp"
DoCmd.DeleteObject acTable, "tbl_Temp"

How can I modify the code to exclude the autonumber primary key field from
the query that runs from the imported table?
 
J

John Vinson

I am using the following code:

'Run append query from temp table to table TrackRecords

DoCmd.RunSQL "INSERT INTO " & strExistingTableName & _
" SELECT tbl_Temp.* " & _
" FROM tbl_Temp"
DoCmd.DeleteObject acTable, "tbl_Temp"

How can I modify the code to exclude the autonumber primary key field from
the query that runs from the imported table?

Only by changing the line

SELECT tblTemp.*

to

SELECT tblTemp.ThisField, ThatField, AnotherField, ...

to select the list of fieldnames that you want to append (i.e. all
fields except the autonumber).

John W. Vinson[MVP]
Join the online Access Chats
Tuesday 11am EDT - Thursday 3:30pm EDT
http://community.compuserve.com/msdevapps
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top