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
Make Table in Back End using VBA code is not creating the table Hugh self taught Microsoft Access VBA Modules 3 18th Jan 2010 01:57 PM
Make Copy of file in one table & copy it to another table =?Utf-8?B?VGVycnk=?= Microsoft Access 5 26th Oct 2006 07:56 PM
Failure to make a copy of table ray Microsoft Access Database Table Design 1 3rd Oct 2004 02:54 AM
Make DB copy using code Karen Microsoft Access Security 0 9th Sep 2004 03:56 PM
Make DB copy using code Karen Microsoft Access External Data 0 9th Sep 2004 03:53 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:07 PM.