copying a table from DB1 to DB2

stuartam

Registered User.
Local time
Today, 12:47
Joined
Jul 16, 2004
Messages
93
Help,
i have a set of databases ( containing back end data ) but its not workgrouped, so what i want to do is now workgroup them.

i have created a blank database that is workgrouped and i want to create some code to copy each table from the un-workgrouped database to the new workgrouped databases.

how do it do this?

i can sort of do it by using the following code, it it dosnt copy the table it recreates it but not with all the attributes of the original, and without the data being in the tables.

Code:
Public Function dbcon(opath As Variant, npath As Variant)
Dim wrk As DAO.Workspace
Dim odb As DAO.Database
Dim ndb As DAO.Database
Dim ntb As DAO.TableDef
Dim nf As DAO.Field
Dim idx As DAO.Index
Set wrk = DBEngine(0)
Set odb = wrk.OpenDatabase(opath)
Set ndb = wrk.OpenDatabase(npath)
For i = 0 To odb.TableDefs.Count - 1
    If Not Left(odb.TableDefs(i).Name, 4) = "MSys" Then
        Call outputtxt("--" & odb.TableDefs(i).Name)
        Set ntb = ndb.CreateTableDef(odb.TableDefs(i).Name)
            For f = 0 To odb.TableDefs(i).Fields.Count - 1
                Call outputtxt("---" & odb.TableDefs(i).Fields(f).Name)
                Set nf = ntb.CreateField(odb.TableDefs(i).Fields(f).Name, odb.TableDefs(i).Fields(f).Type, odb.TableDefs(i).Fields(f).Size)
                nf.Attributes = odb.TableDefs(i).Fields(f).Attributes
                nf.Required = odb.TableDefs(i).Fields(f).Required
                ntb.Fields.Append nf
'                If odb.TableDefs(i).Fields(f).Attributes = 17 Then
'                    Set idx = ntb.CreateIndex("PrimaryKey")
'                    idx.Primary = True
'                    idx.Required = True
'                    idx.Unique = True
'                    idx.Fields.Append
'                    ntb.Indexes.Append idx
'                    ntb.Indexes.Refresh
'                End If
            Next
        ndb.TableDefs.Append ntb
        ndb.TableDefs.Refresh
        
    End If
Next
Set odb = Nothing
Set ndb = Nothing
End Function

their must be a better way to do this?

thanks in advance
 

Users who are viewing this thread

Back
Top Bottom