PC Review


Reply
Thread Tools Rate Thread

Copy table structure in Access 2000

 
 
Del
Guest
Posts: n/a
 
      4th Sep 2008
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?
--
Thank you,
Del
 
Reply With Quote
 
 
 
 
Dirk Goldgar
Guest
Posts: n/a
 
      4th Sep 2008
"Del" <(E-Mail Removed)> wrote in message
news:052D9C4B-E2A6-44D4-86F5-(E-Mail Removed)...
> 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

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

(please reply to the newsgroup)

 
Reply With Quote
 
fredg
Guest
Posts: n/a
 
      4th Sep 2008
On Thu, 4 Sep 2008 09:53:01 -0700, Del wrote:

> 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.

--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
 
Reply With Quote
 
Stuart McCall
Guest
Posts: n/a
 
      4th Sep 2008
"Del" <(E-Mail Removed)> wrote in message
news:052D9C4B-E2A6-44D4-86F5-(E-Mail Removed)...
> 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?
> --
> Thank you,
> Del


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


 
Reply With Quote
 
Del
Guest
Posts: n/a
 
      4th Sep 2008
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.
--
Thank you,
Del


"Dirk Goldgar" wrote:

> "Del" <(E-Mail Removed)> wrote in message
> news:052D9C4B-E2A6-44D4-86F5-(E-Mail Removed)...
> > 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
>
> --
> Dirk Goldgar, MS Access MVP
> www.datagnostics.com
>
> (please reply to the newsgroup)
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
copy table structure =?Utf-8?B?TG9uaSAtIFJXVA==?= Microsoft Access 10 16th Sep 2007 09:52 PM
How do I copy table structure (w/o data) using VB in MS-Access? =?Utf-8?B?S2lt?= Microsoft Access 11 6th Oct 2005 10:57 PM
Copy structure table BB Microsoft Access 7 24th Jun 2005 01:27 PM
copy fields from one table to the field structure of another table Educo Gent Microsoft Access ADP SQL Server 2 10th Feb 2005 05:29 PM
Copy Table Structure Tom Microsoft Access Getting Started 4 7th Jul 2003 05:13 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:56 PM.