Copy Table Structure 
Author Message
 Copy Table Structure

Hi all,

I have a Access97 Table and I want to copy the
structure to create a new table in the same db.
I don't want the records stored in it to come too.

I also need to set a Primary Key in the new table,
Does anybody know how?

At present I can only copy the entire table, and
there is no Primary Key in the duplicate.

Thanks in advance
Gillian



Mon, 18 Feb 2002 03:00:00 GMT  
 Copy Table Structure
Ok, you are almost done ...
For creating the Primary Key you need to add one index to the new table, and
set the Primary property to True, take a look at the online help at the
CreateIndex method for getting one example of the proper syntax.

Good luck

--
Alberto Borbolla
Microsoft VB MVP
Tecnologia en Sistemas Mexico




Mon, 18 Feb 2002 03:00:00 GMT  
 Copy Table Structure


Quote:
> Hi all,

> I have a Access97 Table and I want to copy the
> structure to create a new table in the same db.
> I don't want the records stored in it to come too.

checked code (copied from one of my own progs):

Set td = db.CreateTableDef(tName)
For Each f In db.TableDefs(tName).Fields
    If (f.Attributes And dbSystemField) = 0 Then
        td.Fields.Append td.CreateField(f.Name, f.Type, f.Size)
    End If
Next
db.TableDefs.Append td

Quote:
> I also need to set a Primary Key in the new table,
> Does anybody know how?

Add an index to the tabledef.

Unchecked code I'm making up while typing this, so no guarantees:

set ix = td.createindex(name)
set f = ix.createfield(fname)    ' Use name of field you want to index on
td.indexes.append ix

I usually do this before appending the tabledef to the db, but IIRC you can
add them later too.



Mon, 18 Feb 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. copy table structure

2. Copying table structures in code

3. Newbie: How to copy Table structure?

4. Copying Table structures

5. Newbie: How to copy Table structure?

6. Copying table structure w/ code

7. copying table structure with Openschema

8. HowTo Copy a Recordset from a Table to an identically structured table

9. Copying the structure of a table to a new table

10. Copying the structure of one Access table to a new Access table

11. VB5 & Access 97 Copy Table Structure from One MDB to Another

12. Copy Foxpro 2.6 table structure

 

 
Powered by phpBB® Forum Software