How Do I Copy a table from one Access DB to another Access DB

核能气质少年 提交于 2020-01-06 03:08:07

问题


I am trying to automate a process to create a secondary database from a primary. Both DB's (MS Access) contain one table; the table in the secondary DB is a subset of the table in the primary.

Is there a simple way to copy a recordset frone one DB to another? I am using VBScript and ADO.

Thanks!


回答1:


Try the CopyObject method:

DoCmd.CopyObject "DestinationDatabaseName", "NewName", acTable, "SourceTable"



回答2:


You can run Insert queries referencing external Access database files files (MDB, ACCDB, etc). For example:

strSQL = "INSERT INTO ServiceRecordInvoices " & _
    "( sriID, sriServiceRecordID, sriInvoiceDate, sriInvoiceNumber, " & _
                                "sriDescription, sriInvoiceAmount ) " & _
    " IN '" & strDatabasePathandNameTo & "' " & _
    "SELECT srpID, srpServiceRecordID, srpInvoiceDate, srpInvoiceNumber, " & _
                                "srpParts, srpPartsAmount " & _
    "FROM ServiceRecordParts IN '" & strDatabasePathandNameFrom & "';"

Note the two string variables strDatabasePathandNameTo and strDatabasePathandNameFrom. The above dynamic SQL code will work fine in either DAO or ADO.

If the two tables are identical then you could use the following (untested):

strSQL = "INSERT INTO ServiceRecordInvoices.* " & _
    " IN '" & strDatabasePathandNameTo & "' " & _
    "SELECT * " & _
    "FROM ServiceRecordParts IN '" & strDatabasePathandNameFrom & "';"


来源:https://stackoverflow.com/questions/1209681/how-do-i-copy-a-table-from-one-access-db-to-another-access-db

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!