create table only with structure fileds

User avatar
sal21
PlatinumLounger
Posts: 4370
Joined: 26 Apr 2010, 17:36

create table only with structure fileds

Post by sal21 »

I have a table in access database named TABLE1.
Is possible via VB6 or vba for excel to create, into the same database, a new table balnk named TABLE2 only with the same name and structure of TABLE1?

User avatar
HansV
Administrator
Posts: 78627
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: create table only with structure fileds

Post by HansV »

Try this SQL string

SELECT * INTO TABLE2 FROM TABLE1 WHERE False
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4370
Joined: 26 Apr 2010, 17:36

Re: create table only with structure fileds

Post by sal21 »

HansV wrote:Try this SQL string

SELECT * INTO TABLE2 FROM TABLE1 WHERE False
Hi Hans, sorry for delay, but very busy!
the code work perfect! but not copy the property of index, i need to indexed field1 andf field2 with the duplicates admittet?
Is possible ?

User avatar
HansV
Administrator
Posts: 78627
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: create table only with structure fileds

Post by HansV »

Surely you don't need to do this all the time? You can copy the structure of a table (with all indexes, but without records) easily within Access: simply copy the table, then paste it. The VBA for this (within Access!) would be

DoCmd.TransferDatabase acImport, "Microsoft Access", CurrentProject.FullName, acTable, "TABLE1", "TABLE2", True
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4370
Joined: 26 Apr 2010, 17:36

Re: create table only with structure fileds

Post by sal21 »

HansV wrote:Surely you don't need to do this all the time? You can copy the structure of a table (with all indexes, but without records) easily within Access: simply copy the table, then paste it. The VBA for this (within Access!) would be

DoCmd.TransferDatabase acImport, "Microsoft Access", CurrentProject.FullName, acTable, "TABLE1", "TABLE2", True
OK... but i can to use into a vba for excel, is correct?

User avatar
HansV
Administrator
Posts: 78627
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: create table only with structure fileds

Post by HansV »

Yes, you can use Automation to control Access from VBA in Excel. See Wendell's tutorial Automation 101 for a short introduction and useful links.
Best wishes,
Hans