Copy table structure in Access 2000

D

Del

I'm trying to create a second table in my DB with the same structure as an
existing table but without the data. This code copies both the structure and
the data.

DoCmd.CopyObject , "Table2", acTable, "Table1"

How can I copy just the structure?
 
D

Dirk Goldgar

Del said:
I'm trying to create a second table in my DB with the same structure as an
existing table but without the data. This code copies both the structure
and
the data.

DoCmd.CopyObject , "Table2", acTable, "Table1"

How can I copy just the structure?


If you want to do it manually, you can copy and paste, choosing "Structure
Only" when prompted. If you want to do it programmatically, you can use
TransferDatabase, specifying the current database as the target of an export
and giving True for the StructureOnly argument, like this:

Docmd.TransferDatabase acExport, "Microsoft Access", _
CurrentDb.Name, acTable, _
"Table1", "Table2", _
True
 
F

fredg

I'm trying to create a second table in my DB with the same structure as an
existing table but without the data. This code copies both the structure and
the data.

DoCmd.CopyObject , "Table2", acTable, "Table1"

How can I copy just the structure?

You can simply select the existing table,right-click copy, then
right-click and select Paste. When the renaming dialog comes up click
on Structure only.

If you need to do this via code, have you tried deleting the data from
the new table after you copy the existing table?

DoCmd.CopyObject , "Table2", acTable, "Table1"
CurrentDb.Execute "Delete Table2.* From Table2;",dbFailOnError

Then compact the database.
 
S

Stuart McCall

Del said:
I'm trying to create a second table in my DB with the same structure as an
existing table but without the data. This code copies both the structure
and
the data.

DoCmd.CopyObject , "Table2", acTable, "Table1"

How can I copy just the structure?

TransferDatabase will do the job. Just specify CurrentDb.Name for the
receiving database.

DoCmd.TransferDatabase acExport, "Microsoft Access", _
CurrentDb.Name, acTable, "SourceTableName", _
"DestinationTableName", StructureOnly:=True
 
D

Del

Thanks, this worked for me.

There is one confusing thing. The default for the database type is supposed
to be Microsoft Access, but when I leave it blank (comma only) I get an
error. Oh well.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top