Copying tabledefs between databases 
Author Message
 Copying tabledefs between databases

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



Sun, 07 Feb 1999 03:00:00 GMT  
 Copying tabledefs between databases

Quote:

> 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!



Sun, 07 Feb 1999 03:00:00 GMT  
 Copying tabledefs between databases

Quote:

> 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



Sun, 07 Feb 1999 03:00:00 GMT  
 Copying tabledefs between databases

Quote:

> 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



Sun, 07 Feb 1999 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Trying to copy DAO.Field object between TableDefs

2. copy tabledefs with ado

3. Copy line of one Database to another Database

4. how to copy a record from one database to another database with the same struture

5. how copy records from databases to databases ?

6. Copying the contents of a table in one database to another database

7. MS Access DB - Copy Table A from Database A to Table A Database B

8. Help: copying database data into new database

9. Copying records from jet database to a new jet database

10. Copying the contents of a table in one database to another database

11. TableDefs Refreshing

12. TableDefs issue

 

 
Powered by phpBB® Forum Software