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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copy table from a different database

Status
Not open for further replies.

ossse

Programmer
Jun 26, 2007
49
US
I am trying to copy an entire table (fields and records) from a different database. I used the same code to copy a query and it worked, however for a table it is not working at all. Below is my code, can you please try to figure out where I am going wrong. Also, is there a way to auto-allign the code?

Note: "H:\Projects\ReliaBuilder\Jeff's Screw around files\Bill Duncan\heater + #.mdb" = Location of desired database
"criticality" = name of desired table



Sub ImportTable()

Dim ThisDb As Database, ThatDB As Database
Dim NewTabl As TableDef
Dim DbName As String
Dim ThatTabl As TableDef

'Database with desired table
DbName = "H:\Projects\ReliaBuilder\Jeff's Screw around files\Bill Duncan\heater + #.mdb"

Set ThisDb = CurrentDb()

Set ThatDB = DBEngine.Workspaces(0).OpenDatabase(DbName)

'desired table
Set ThatTabl = ThatDB.TableDefs("criticality")
Set NewTabl = ThisDb.CreateTableDef(ThatTabl.Name, ThatTabl.Attributes)

End Sub
 
In Access VBA you may use the CopyObject or TransferDatabase methods of the DoCmd object.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top