Need to copy object using macro

ashishprem

Registered User.
Local time
Today, 12:33
Joined
Mar 18, 2008
Messages
35
Hi,

I have a macro written in file1.mdb. This maro should copy a table from
file2.mdb and paste in a third file file3.mdb.
When i use docmd command it gives me a option to define the destination database but I am unable to define the source database which is file2.mdb. By default it takes file1.mdb. Any way to define the source object as file2.mdb

Thanks in adv for help.

Ashish
 
I don't know the answer to how to do this in a macro, but you should consider doing this in a module instead (or maybe that is what you are asking, since this is the modules discussion). To export a table to a different database, you will need something like this:
Code:
DoCmd.TransferDatabase acExport, "Microsoft Access", FullExportPath, acTable, SourceTableName, DestinationTableName
You can look in the help under transfer database method to get more information on the arguments.
HTH
 
I have a macro written in file1.mdb. This maro should copy a table from
file2.mdb and paste in a third file file3.mdb.

What you can do is use a combination of TransferDatabase and CopyObject.

Use TransferDatabase to import the table from file2.mdb to file1.mdb and then you can export it to file3.mdb from file1.mdb and that solves the problem

However, to do this (if it is on a regular basis) you need DeleteObject to the delete the imported table after the CopyObject action other wise next time you import the imported table will have a 1 at the end of the name and a 2 and a 3 etc each time you import.

Do all of this in one macro. Just make sure the order of the macro actions is correct.

If the table you are importing has the same name as a table in file1.mdb then use the Rename action. Use this action to rename the table in File1.mdb and then at the end of the macro use Rename again to bring it back to original name
 
Last edited:

Users who are viewing this thread

Back
Top Bottom