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.
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.