Link to home
Start Free TrialLog in
Avatar of Sankar_V
Sankar_V

asked on

Import Tables From one Database to the Other!

Hi All!

i use this code to create link between databases!

i got this code from vbcode.com

can anybody tell me that hw can i do the import tables function??

even i dont require in same format........but what ever easier and effective!

Dim dbname As String
Dim Eng As String
Dim DESIGNREPORTS As Database
Dim engcn As ADODB.Connection
Dim engcat As ADOX.Catalog
Dim engtbl As ADOX.Table
Dim tablename As String
Dim suitecat As ADOX.Catalog
Dim suitecn As ADODB.Connection
Dim suitetbl As ADOX.Table
Dim designcat As ADOX.Catalog
Dim designcn As ADODB.Connection
Dim designtbl As ADOX.Table


Private Sub Command2_Click()
dbname = "D:\My Documents\Access Files\Budget.mdb"
Eng = "D:\My Documents\Access Files\Copy of db1.mdb"
Set engcn = New ADODB.Connection
   engcn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Eng & ""
   
   Set suitecn = New ADODB.Connection
   suitecn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbname & ""
   
   Set engcat = New ADOX.Catalog
   Set suitecat = New ADOX.Catalog
   
   
    engcat.ActiveConnection = engcn
    suitecat.ActiveConnection = suitecn
    For Each suitetbl In suitecat.Tables
    If suitetbl.Type = "TABLE" Then
    Set engtbl = New ADOX.Table
    tablename = suitetbl.Name
    engtbl.Name = tablename
    Set engtbl.ParentCatalog = engcat
    engtbl.Properties("Jet OLEDB:Link Datasource") = dbname
    engtbl.Properties("Jet OLEDB:Remote Table Name") = tablename
    engtbl.Properties("Jet OLEDB:Create Link") = True
    engcat.Tables.Append engtbl
    End If
    Next
   
End Sub
ASKER CERTIFIED SOLUTION
Avatar of makman
makman

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Sankar_V
Sankar_V

ASKER

Thanks makman!

Thanks for ur reference!

I got the result which i want!

Thanks a lot!