PC Review


Reply
Thread Tools Rate Thread

How can i make a copy of a table thru code?

 
 
Mota
Guest
Posts: n/a
 
      24th Nov 2004
Hi;
I want to make a table in my DB,based on another table.I used the "SELECT
......INTO" statement of SQL,but the field properties in the new made table
are not the same.For example,the Primary Key of the base table (that is just
a sample and empty table) would not go to the new table.Also for the "Allow
zero legth","Default Value" properties and so on.
I tried CreateTableDef method of the Current database in DAO,but i couldnt
work with it and failed.In fact,when i want to append new TableDef to its
collection,an error says that new TableDef has no Fields,and when i try to
append fields of the sample Table to it,another error says that an object
(Field) with this name already exist in the new TableDef.In addition,im not
sure of Field Properties inheritance in this method.
Can anyone please help me to make a table based on another one,just like its
parent,in the field properties?
I use Access 2000.
Thank you in advance.


 
Reply With Quote
 
 
 
 
Graham R Seach
Guest
Posts: n/a
 
      24th Nov 2004
Mota,

You can try either the CopyObject or TransferDatabase methods of the DoCmd
object.

DoCmd.CopyObject CurrentDb.Name, "tblMyNewTable", acTable,
"tblMyExistingTable"

DoCmd.TransferDatabase acImport, "Microsoft Access", CurrentDb.Name,
acTable, "tblMyExistingTable", "tblMyNewTable", False

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia

Microsoft Access 2003 VBA Programmer's Reference
http://www.wiley.com/WileyCDA/WileyT...764559036.html


"Mota" <(E-Mail Removed)> wrote in message
news:eG$(E-Mail Removed)...
> Hi;
> I want to make a table in my DB,based on another table.I used the "SELECT
> .....INTO" statement of SQL,but the field properties in the new made table
> are not the same.For example,the Primary Key of the base table (that is
> just
> a sample and empty table) would not go to the new table.Also for the
> "Allow
> zero legth","Default Value" properties and so on.
> I tried CreateTableDef method of the Current database in DAO,but i couldnt
> work with it and failed.In fact,when i want to append new TableDef to its
> collection,an error says that new TableDef has no Fields,and when i try to
> append fields of the sample Table to it,another error says that an object
> (Field) with this name already exist in the new TableDef.In addition,im
> not
> sure of Field Properties inheritance in this method.
> Can anyone please help me to make a table based on another one,just like
> its
> parent,in the field properties?
> I use Access 2000.
> Thank you in advance.
>
>



 
Reply With Quote
 
 
 
 
MacDermott
Guest
Posts: n/a
 
      24th Nov 2004
While it is possible to do this programmatically, it's pretty rare for this
to be a good database design.
Putting the same data into two tables leaves you no reliable way to keep the
two copies synchronized.

"Mota" <(E-Mail Removed)> wrote in message
news:eG$(E-Mail Removed)...
> Hi;
> I want to make a table in my DB,based on another table.I used the "SELECT
> .....INTO" statement of SQL,but the field properties in the new made table
> are not the same.For example,the Primary Key of the base table (that is

just
> a sample and empty table) would not go to the new table.Also for the

"Allow
> zero legth","Default Value" properties and so on.
> I tried CreateTableDef method of the Current database in DAO,but i couldnt
> work with it and failed.In fact,when i want to append new TableDef to its
> collection,an error says that new TableDef has no Fields,and when i try to
> append fields of the sample Table to it,another error says that an object
> (Field) with this name already exist in the new TableDef.In addition,im

not
> sure of Field Properties inheritance in this method.
> Can anyone please help me to make a table based on another one,just like

its
> parent,in the field properties?
> I use Access 2000.
> Thank you in advance.
>
>



 
Reply With Quote
 
Mota
Guest
Posts: n/a
 
      24th Nov 2004
I dont want to Synch them.
Thank you for ur comment.

"MacDermott" <(E-Mail Removed)> wrote in message
news:u2cV$(E-Mail Removed)...
> While it is possible to do this programmatically, it's pretty rare for

this
> to be a good database design.
> Putting the same data into two tables leaves you no reliable way to keep

the
> two copies synchronized.
>
> "Mota" <(E-Mail Removed)> wrote in message
> news:eG$(E-Mail Removed)...
> > Hi;
> > I want to make a table in my DB,based on another table.I used the

"SELECT
> > .....INTO" statement of SQL,but the field properties in the new made

table
> > are not the same.For example,the Primary Key of the base table (that is

> just
> > a sample and empty table) would not go to the new table.Also for the

> "Allow
> > zero legth","Default Value" properties and so on.
> > I tried CreateTableDef method of the Current database in DAO,but i

couldnt
> > work with it and failed.In fact,when i want to append new TableDef to

its
> > collection,an error says that new TableDef has no Fields,and when i try

to
> > append fields of the sample Table to it,another error says that an

object
> > (Field) with this name already exist in the new TableDef.In addition,im

> not
> > sure of Field Properties inheritance in this method.
> > Can anyone please help me to make a table based on another one,just like

> its
> > parent,in the field properties?
> > I use Access 2000.
> > Thank you in advance.
> >
> >

>
>



 
Reply With Quote
 
Mota
Guest
Posts: n/a
 
      24th Nov 2004
Thank you for ur help.

"Graham R Seach" <(E-Mail Removed)> wrote in message
news:#(E-Mail Removed)...
> Mota,
>
> You can try either the CopyObject or TransferDatabase methods of the DoCmd
> object.
>
> DoCmd.CopyObject CurrentDb.Name, "tblMyNewTable", acTable,
> "tblMyExistingTable"
>
> DoCmd.TransferDatabase acImport, "Microsoft Access", CurrentDb.Name,
> acTable, "tblMyExistingTable", "tblMyNewTable", False
>
> Regards,
> Graham R Seach
> Microsoft Access MVP
> Sydney, Australia
>
> Microsoft Access 2003 VBA Programmer's Reference
> http://www.wiley.com/WileyCDA/WileyT...764559036.html
>
>
> "Mota" <(E-Mail Removed)> wrote in message
> news:eG$(E-Mail Removed)...
> > Hi;
> > I want to make a table in my DB,based on another table.I used the

"SELECT
> > .....INTO" statement of SQL,but the field properties in the new made

table
> > are not the same.For example,the Primary Key of the base table (that is
> > just
> > a sample and empty table) would not go to the new table.Also for the
> > "Allow
> > zero legth","Default Value" properties and so on.
> > I tried CreateTableDef method of the Current database in DAO,but i

couldnt
> > work with it and failed.In fact,when i want to append new TableDef to

its
> > collection,an error says that new TableDef has no Fields,and when i try

to
> > append fields of the sample Table to it,another error says that an

object
> > (Field) with this name already exist in the new TableDef.In addition,im
> > not
> > sure of Field Properties inheritance in this method.
> > Can anyone please help me to make a table based on another one,just like
> > its
> > parent,in the field properties?
> > I use Access 2000.
> > Thank you in advance.
> >
> >

>
>



 
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
Smartphone2003, cant access internet thru app, but can thru IE rpatel4@gmail.com Microsoft Dot NET Compact Framework 0 7th Sep 2006 02:40 PM
Appending Table name into another table table thru SQL query =?Utf-8?B?UGx1bWRvZGdl?= Microsoft Access Queries 1 10th Dec 2005 06:32 AM
WinXPPro - can't google thru IntExplorer and can't search thru WinExplorer baz Windows XP Basics 7 15th Jun 2005 03:03 AM
WinXPPro - can't google thru IntExplorer and can't search thru WinExplorer baz Windows XP Help 1 14th Jun 2005 01:58 PM
Overclocking thru Windows or thru the BIOS? David Mills Windows XP Hardware 2 21st Jan 2005 07:42 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:53 PM.