I have some ODBC-linked SQL-Server tables in my Access DB, which are the production environment. For testing I want to copy all the data from the SQL-Server into structure-identical Access tables so that I have an identical set of tables in a dev or test-environment. To make it difficult: All of these tables have autoincrement IDs and I want the copies to have the same values and of course the copied ID field also as autoincrement long.
So, a set of these tables:
- dbo_tbl_Abcd
- dbo_tbl_Efgh etc.
should be copied to:
- Dev_Abcd
- Dev_Efgh etc.
or to:
- Test_Abcd
- Test_Efgh etc.
When I do a manual copy and paste for each single table this will work without problems. A dialog "Paste Table As" appears where you have the options:
Linked Table
Structure Only
Structure and Data
Append Data to Existing Table
When you set the name correctly and choose Structure and Data, you will have a proper copy as Access table with the same values in the Auto-ID field. I just want to do this by code and for all ODBC-Tables at once (in a loop). When Access provides this manual copying, there must be a way to do this by code.
I have already tried this:
DoCmd.CopyObject , "Dev_Abcd", acTable, "dbo_tbl_Abcd"
but this only will create more ODBC-links to the same SQL-Server tables. I also tried this:
DoCmd.TransferDatabase acExport, "Microsoft Access", CurrentDb.Name, acTable, "dbo_tbl_Abcd", "Dev_Abcd"
This led to the following error:
The Microsoft Access database engine could not find the object . Make sure the object exists and that you spell its name and the path name correctly. (Error 3011)
I experimented a lot with DoCmd.TransferDatabase, but cound't find a working setting.
I did not test any "SELECT INTO"-Statements because of the autoincrement field.
SELECT ... INTO ...
and auto-increment fields? It generally works great for me. – Erik ADoCmd.TransferDatabase acImport, "ODBC", "your ODBC_String", ...
could work. – Andre