How do I copy only the structure of a table?

  • Thread starter Margaret Bartley
  • Start date
M

Margaret Bartley

The DoCmd.CopyObject method does not have an argument that flags whether to
copy all the data, or just the structure. Is there a way in VBA code to
copy only the structure of a table, and not the data?

Many thanks,
Margaret
 
A

Alex Dybenko

Hi,
perhaps you can first copy whole table, and then delete data.
other option - you have to write a code to go throught all fields,
properties, indexes, etc of a table and create same on a new one
 
D

Dirk Goldgar

Margaret Bartley said:
The DoCmd.CopyObject method does not have an argument that flags
whether to copy all the data, or just the structure. Is there a way
in VBA code to copy only the structure of a table, and not the data?

DoCmd.TransferDatabase will do it. Just specify the current database's
name as the target database, and specify True for the StructureOnly
argument. For example,

DoCmd.TransferDatabase _
acExport, _
"Microsoft Access", _
CurrentDb.Name, _
acTable, _
"Table1", _
"Table1_COPY", _
True
 
D

Dirk Goldgar

Alex Dybenko said:
Hi,
perhaps you can first copy whole table, and then delete data.
other option - you have to write a code to go throught all fields,
properties, indexes, etc of a table and create same on a new one

There's a Microsoft KnowledgeBase article for Access 97 on how to do
this with DAO:

http://support.microsoft.com/default.aspx?scid=kb;en-us;217011

I don't think there's a version of the article for Access 2000+, but I
imagine that article would work for these versions, too. However, using
TransferDatabase seems simplest.
 
M

Margaret Bartley

Ooh, Thank You!!

Dirk Goldgar said:
DoCmd.TransferDatabase will do it. Just specify the current database's
name as the target database, and specify True for the StructureOnly
argument. For example,

DoCmd.TransferDatabase _
acExport, _
"Microsoft Access", _
CurrentDb.Name, _
acTable, _
"Table1", _
"Table1_COPY", _
True

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 

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