Copying tabledefs between databases

Copying tabledefs between databases

Post by Mithri » Thu, 22 Aug 1996 04:00:00



Can anyone help me with a problem I have creating copies of a datebase.
The application I am developing (VB4.0 32 Prof/Jet 3.0) has a seperate
database for each project, that need to be created 'on the fly'. The
tables required are stored in a central .mdb file and I need to copy
them into each project database. I suppose I could create them anew each
time but this seems like the long way round.
I hope someone can help.

Neil D. Rankin

 
 
 

Copying tabledefs between databases

Post by Joe Fost » Thu, 22 Aug 1996 04:00:00



> Can anyone help me with a problem I have creating copies of a datebase.
> The application I am developing (VB4.0 32 Prof/Jet 3.0) has a seperate
> database for each project, that need to be created 'on the fly'. The
> tables required are stored in a central .mdb file and I need to copy
> them into each project database. I suppose I could create them anew each
> time but this seems like the long way round.
> I hope someone can help.

Do you need to copy just the structures, or the structure and the
data? What about indexes or relationships between tables? You
could open up both databases (RTFM CreateDatabase if you need to
create new MDB's dynamically) and copy the TableDefs using
CreateTableDef, CreateField, CreateIndex, and CreateRelation and
then copy over the various properties. If you need to copy the
data too, I'd do this before copying the indexes and
relationships. You might run into trouble with counters, but I
think VB 3.0 at least supports overriding a counter's default
value. Anyway, here's some untested code off the top of my head
to copy data from one Recordset to another:

Sub CopyRecordset (Src As Recordset, Dst As Recordset)
    Dim MaxFieldID As Integer: MaxFieldID = Src.Fields.Count - 1
    If (Src.RecordCount > 0) Then Src.MoveFirst
    While (Src.EOF = False)
        Dst.AddNew
        Dim f As Integer: For f = 0 to MaxFieldID
            Select Case Dst(f).Type
            Case DB_MEMO, DB_LONGBINARY:
                Dim FL As Long: FL = Src(f).FieldSize
                Dim i As Long: i = 0
                While (i < FL)
                    Dim buf As String
                    If (FL - i >= 4096) Then
                        buf = Src(f).GetChunk(i, 4096)
                    Else
                        buf = Src(f).GetChunk(i, FL - i)
                    End If
                    Dst(f).AppendChunk buf
                    i = i + Len(buf)
                Wend
            Case Else:
                Dst(f) = Src(f)
            End Select
        Next f
        Dst.Update
    Wend
End Sub

--

WARNING: I cannot be held responsible for the above        They're   coming  to
because  my cats have  apparently  learned to type.        take me away, ha ha!

 
 
 

Copying tabledefs between databases

Post by Peter Larsso » Thu, 22 Aug 1996 04:00:00



> Can anyone help me with a problem I have creating copies of a datebase.
> The application I am developing (VB4.0 32 Prof/Jet 3.0) has a seperate
> database for each project, that need to be created 'on the fly'. The
> tables required are stored in a central .mdb file and I need to copy
> them into each project database. I suppose I could create them anew each
> time but this seems like the long way round. I hope someone can help.

This files can also help You:
http://www.microsoft.com/kb/softlib/mslfiles/neatcode.exe
http://www.microsoft.com/kb/softlib/mslfiles/neatcod2.exe

Peter Larsson

 
 
 

Copying tabledefs between databases

Post by Peter Larsso » Thu, 22 Aug 1996 04:00:00



> Can anyone help me with a problem I have creating copies of a datebase.
> The application I am developing (VB4.0 32 Prof/Jet 3.0) has a seperate
> database for each project, that need to be created 'on the fly'. The
> tables required are stored in a central .mdb file and I need to copy
> them into each project database. I suppose I could create them anew each
> time but this seems like the long way round. I hope someone can help.

Download this code from Microsoft:
http://www.microsoft.com/ACCESSDEV/accwhite/TbCCWiz.EXE

Peter Larsson