1

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!

3
  • Do you have SQL server available? Commented Jul 30, 2009 at 22:19
  • Is this a one time job? If you could, create a link table from base table into seconday table. The code then will become much simpler. Commented Jul 30, 2009 at 23:02
  • Couldn't you just copy the file? Commented Jul 31, 2009 at 15:11

2 Answers 2

1

Try the CopyObject method:

DoCmd.CopyObject "DestinationDatabaseName", "NewName", acTable, "SourceTable"
Sign up to request clarification or add additional context in comments.

Comments

0

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 & "';"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.