I’ve inherited a setup that utilizes Access 97 databases. I need to copy a table from one main mdb to multiple others to prep them for use. The source mdb and source table are mostly static, the destination mdbs vary widely.
So, I have:
source.mdb contains table A
destination.mdb contains tables 1, 2, and 3
I need to end up with:
source.mdb is unchanged (contains table A)
destination.mdb contains tables 1, 2, 3, and A
This is a simple enough task within the Access GUI, but because this task needs to happen hundreds of times in a day, I’d like to automate it. The ultimate goal is to have a script or batchfile that I can give each mdb user (about 75 employees) to manipulate each database on their own before use. I’m much more at home in a UNIX/Oracle environment, so scripting this up has thrown me for a loop.
In Oracle, I would use a query like this:
copy from user/password@sourceDB to user/password@destinationDB
create new_tableA using select * from tableA;
A similar question here on stack overflow tells how to copy records from one table to another, but the destination table pre-exists, and particular fields are defined:
strSQL = “INSERT INTO ServiceRecordInvoices ” & _
“( sriID, sriServiceRecordID, sriInvoiceDate, sriInvoiceNumber, ” & _
“sriDescription, sriInvoiceAmount ) ” & _
” IN ‘” & strDatabasePathandNameTo & “‘ ” & _
“SELECT srpID, srpServiceRecordID, srpInvoiceDate, srpInvoiceNumber, ” & _
“srpParts, srpPartsAmount ” & _
“FROM ServiceRecordParts IN ‘” & strDatabasePathandNameFrom & “‘;”
My first try looks like this and unsurprisingly, doesn’t work. Can someone steer me right?
copyTableSql = “CREATE [new_tableA] ” & _
” IN ‘” & destinationDBpath & “‘ ” & _
“SELECT * FROM tableA IN ‘” & sourceDBpath & “‘;”
Thanks for any advice.
If you’re willing to use VBA within Access to automate this task, it would be easy with a “SELECT … INTO …” statement — what Access calls a Make Table Query.
If you must drive it with scripting outside of Access, try vbscript similar to this:
I tested that script with my own database and table names, and it works for me with Access 2007. You may need to reference a different DAO version for Access 97. I don’t know which version you need, but would probably start with “DAO.DBEngine.35” for the CreateObject line.
Actually, this task would be simpler if you create a link in destination.mdb which points to tblA in source.mdb. That way you wouldn’t have to copy data from one database to the other.