Copying tables using VBA

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How do I copy and paste the "structure only" of a table in Access using
Visual Basic?

When using the "copyobject" command, it copies the entire table (including
data). I just want to copy the structure of the table.

Thanks for any help!
 
O_dog said:
How do I copy and paste the "structure only" of a table in Access
using Visual Basic?

When using the "copyobject" command, it copies the entire table
(including data). I just want to copy the structure of the table.

OldTable = xxxx
newtable = xxxx

sql = "SELECT * INTO " & NewTable & " FROM " & OldTable & " " & _
"WHERE PKID=0;"

currentdb.execute sql

Important is that the where-criteria is designed
to get no records.
.... WHERE PKID=0; or WHERE not 1=1;

Acki
 
Jörg Ackermann said:
OldTable = xxxx
newtable = xxxx

sql = "SELECT * INTO " & NewTable & " FROM " & OldTable & " " & _
"WHERE PKID=0;"

currentdb.execute sql

Important is that the where-criteria is designed
to get no records.
... WHERE PKID=0; or WHERE not 1=1;

The only trouble with that is that it copies only the fields, not
indexes -- so you don't get exactly the same thing as if you copied and
pasted the table and selected "Structure Only". But you can do this:

DoCmd.TransferDatabase _
acExport, "Microsoft Access", _
CurrentDb.Name, _
acTable, "OldTable", "NewTable", _
True
 
Back
Top