Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copy Table Routine

Status
Not open for further replies.

ormsk

Programmer
Sep 30, 2002
147
GB
I have already checked the forums for this specific problem, but with no success.

I am creating a routine in DB (A) and I want to copy a table from DB (B) to DB (C). I have looked at the TransferDatabase command, but this only appears to allow you to copy an object into the CURRENT DB.

**********************************
There is more than one way to skin a cat...but who wants a skinned cat?
 
The DoCmd. is supposed to do work on the current database. If you need to do what you describe you 'll have to create a new access instance and use on that instance the docmd.

Code:
Dim objAccess As Object
Const strDB1 As String = "C:\DataFiles\myDB1.mdb"
Const strDB2 As String = "C:\DataFiles\myDB2.mdb"

Set objAccess = CreateObject("Access.Application")
objAccess.OpenCurrentDatabase strDB1
objAccess.DoCmd.CopyObject strDB2, acTable, "Your_TableName_Of_myDB1"
objAccess.CloseCurrentDatabase
objAccess.Quit
Set objAccess = Nothing
 
Or try SQL:
Code:
Dim strSQL As String
Dim dbFrom As String, dbTo As String
Dim db As Database

dbFrom = "C:\Tek-TipsA.mdb"
dbTo = "C:\Tek-TipsB.mdb"

Set db = OpenDatabase(dbFrom)
strSQL = "SELECT Table1Exp.* INTO Table1Exp IN '" & dbTo & "' FROM Table1Exp"
db.Execute strSQL, dbFailOnError
 
If you are trying to copy an object from a db in which you are ..
only a single line of code will do the work
Code:
DoCmd.CopyObject "C:\Northwind.mdb", "tblNewCopy", acTable, "tblContacts"

________________________________________________________
Zameer Abdulla
Help to find Missing people
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top