简体   繁体   中英

Export table to another access database

I have a query in my Access database and a table with absolutely the same structure in another Access database. I'm need to write a script which adds all entries from the query to the table. How can I do this?

The difference between my task and functionality of Extarnal Data -> Export -> Access Database is that I need to add new entries and save the old, but this tool can only replace old entries to new.

  1. Create a linked table in the source database, to the destination table.
  2. Then, use an append query to insert the results from your query into the linked table.

Edit: You can also do this with a single SQL statement:

INSERT INTO DestinationTable (Field1, Field2)
IN "C:\path\to\file.accdb"
SELECT Field1,Field2
FROM SourceTable

But the reference says:

For improved performance and ease of use, use a linked table instead of IN.

For anyone looking to link the table in VBA...

strDbName = "C:\FolderPath\DatabaseName.mdb"
strLinkTbl = "tblNameOfTableYouWantToLink"
strNameTbl = "tblWhatYouWantToNameIt" ' This can be the actual 
                                      ' table name or something different

DoCmd.TransferDatabase acLink, "Microsoft Access", strDbName, _
    acTable, strLinkTbl, strNameTbl

Then your SQL looks like:

CurrentDb.Execute "INSERT INTO " & strNameTbl _
   & " (Field1, Field) SELECT Field1, Field2 FROM SourceTable

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM