PC Review


Reply
Thread Tools Rate Thread

Creating a empty table from an existing table

 
 
=?Utf-8?B?QmlsbCBCcmlua3dvcnRo?=
Guest
Posts: n/a
 
      21st Feb 2005
At the end of the year i want the user to press a button, and it will take
the records out of the table and reset the autonumber file to #1, but i
haven't been able to do it. Because one of the tables has to have one
beginning record in it i thought i would create a dummy table and when the
button is pressed it would delete the existing table and copy the dummy
(predesigned table) and rename it properly - But i need some help in doing
so. I don't know how to do either function in code, although i've looked in
the knowledge base, manuals, etc. Can you help?

Thanks in advance...you've helped me out of the ditch before.
 
Reply With Quote
 
 
 
 
Tim Ferguson
Guest
Posts: n/a
 
      21st Feb 2005
=?Utf-8?B?QmlsbCBCcmlua3dvcnRo?=
<(E-Mail Removed)> wrote in
news:84EC2EE3-5FAD-4115-AC4F-(E-Mail Removed):

> At the end of the year i want the user to press a button, and it will
> take the records out of the table and reset the autonumber file to #1,
> but i haven't been able to do it.


Compacting a database will set empty tables' autonumbers back to one.

But: If You Care What Value An Autonumber Has, You Probably Shouldn't Be
Using An Autonumber.

> Because one of the tables has to
> have one beginning record in it


Unless this record represents real data, I would be very suspicious of a
Design Problem here.

> I thought i would create a dummy table
> and when the button is pressed it would delete the existing table and
> copy the dummy (predesigned table) and rename it properly


// remove the old one
DROP TABLE MyOldTable

// and use a maketable query to copy the master table over
SELECT *
INTO MyOldTable
FROM MyMasterTable

Here is some example code:
' you can use a CurrentProject().Connection too if you
' prefer ADO
Set db = CurrentDB()

' the first command; you can only do one at a time
strSQL = "DROP TABLE MyOldTable;"
db.Execute strSQL, dbFailOnError

' the second command
strSQL = "SELECT * INTO MyOldTable FROM MyMasterTable;"
db.Execute strSQL, dbFailOnError

If MyOldTable is related to other ones, you have to tear down and rebuild
the relationships, indexes and so on. Before you spend a great deal of
time on this, though, I would question how badly you really need to rip
out this table. Why not just delete all but the first record?

HTH


Tim F


 
Reply With Quote
 
=?Utf-8?B?QmlsbCBCcmlua3dvcnRo?=
Guest
Posts: n/a
 
      21st Feb 2005
if i delete all but the first record, i won't be able to renumber them and
that is what i'm trying to accomplish: to sent autonumber to #1.

I tried docmd.deleteobject and docmd.copyobject but because the data is
linked to the program, it won't work. I'd have to relink with code and i
don't know how to do that either.....


"Tim Ferguson" wrote:

> =?Utf-8?B?QmlsbCBCcmlua3dvcnRo?=
> <(E-Mail Removed)> wrote in
> news:84EC2EE3-5FAD-4115-AC4F-(E-Mail Removed):
>
> > At the end of the year i want the user to press a button, and it will
> > take the records out of the table and reset the autonumber file to #1,
> > but i haven't been able to do it.

>
> Compacting a database will set empty tables' autonumbers back to one.
>
> But: If You Care What Value An Autonumber Has, You Probably Shouldn't Be
> Using An Autonumber.
>
> > Because one of the tables has to
> > have one beginning record in it

>
> Unless this record represents real data, I would be very suspicious of a
> Design Problem here.
>
> > I thought i would create a dummy table
> > and when the button is pressed it would delete the existing table and
> > copy the dummy (predesigned table) and rename it properly

>
> // remove the old one
> DROP TABLE MyOldTable
>
> // and use a maketable query to copy the master table over
> SELECT *
> INTO MyOldTable
> FROM MyMasterTable
>
> Here is some example code:
> ' you can use a CurrentProject().Connection too if you
> ' prefer ADO
> Set db = CurrentDB()
>
> ' the first command; you can only do one at a time
> strSQL = "DROP TABLE MyOldTable;"
> db.Execute strSQL, dbFailOnError
>
> ' the second command
> strSQL = "SELECT * INTO MyOldTable FROM MyMasterTable;"
> db.Execute strSQL, dbFailOnError
>
> If MyOldTable is related to other ones, you have to tear down and rebuild
> the relationships, indexes and so on. Before you spend a great deal of
> time on this, though, I would question how badly you really need to rip
> out this table. Why not just delete all but the first record?
>
> HTH
>
>
> Tim F
>
>
>

 
Reply With Quote
 
Tim Ferguson
Guest
Posts: n/a
 
      22nd Feb 2005
=?Utf-8?B?QmlsbCBCcmlua3dvcnRo?=
<(E-Mail Removed)> wrote in
news:B63804BC-5DCA-43C8-B6E6-(E-Mail Removed):

>
> if i delete all but the first record, i won't be able to renumber them
> and that is what i'm trying to accomplish: to sent autonumber to #1.


<yawn /> If this is important, then you probably have a Design Problem.
See DB commandment number 7 as quoted in my post.

> I tried docmd.deleteobject and docmd.copyobject but because the data
> is linked to the program, it won't work. I'd have to relink with code
> and i don't know how to do that either.....


Not sure what you mean by "linked to the program"...

One way to get round relationships, if there are any, would be to empty
the table and then put back your dummy row:-

DELETE FROM MyOldTable;

INSERT INTO MyOldTable (IDNum, FieldOne, FieldTwo)
SELECT ID, One, Two FROm MyMasterTable;

(if the dummy record is not going to change, you could even get rid of
the dummy table altogether by embedding the values sic:-

INSERT INTO MyOldTable (IDNum, FieldOne, FieldTwo)
VALUES (1, NULL, "This is a dummy record");

Of course, this will not reset the autonumber, but then again it
shouldn't matter. Seriously: I have severe misgivings that your project
needs a Design Revision. This is not what autonumbers are meant to do.

All the best


Tim F

 
Reply With Quote
 
John Spencer (MVP)
Guest
Posts: n/a
 
      25th Feb 2005
Take another look at
DoCmd.CopyObject

Put a your "default" table into your front-end. You can then copy that to your backend.

DoCmd.CopyObject "C:\My Documents\Copy of NewsgroupAnswers.mdb", "faqtest",
acTable, "Faqsrc"

You will get a warning message that the old table already exists, but you can
still replace it.

Tim Ferguson wrote:
>
> =?Utf-8?B?QmlsbCBCcmlua3dvcnRo?=
> <(E-Mail Removed)> wrote in
> news:B63804BC-5DCA-43C8-B6E6-(E-Mail Removed):
>
> >
> > if i delete all but the first record, i won't be able to renumber them
> > and that is what i'm trying to accomplish: to sent autonumber to #1.

>
> <yawn /> If this is important, then you probably have a Design Problem.
> See DB commandment number 7 as quoted in my post.
>
> > I tried docmd.deleteobject and docmd.copyobject but because the data
> > is linked to the program, it won't work. I'd have to relink with code
> > and i don't know how to do that either.....

>
> Not sure what you mean by "linked to the program"...
>
> One way to get round relationships, if there are any, would be to empty
> the table and then put back your dummy row:-
>
> DELETE FROM MyOldTable;
>
> INSERT INTO MyOldTable (IDNum, FieldOne, FieldTwo)
> SELECT ID, One, Two FROm MyMasterTable;
>
> (if the dummy record is not going to change, you could even get rid of
> the dummy table altogether by embedding the values sic:-
>
> INSERT INTO MyOldTable (IDNum, FieldOne, FieldTwo)
> VALUES (1, NULL, "This is a dummy record");
>
> Of course, this will not reset the autonumber, but then again it
> shouldn't matter. Seriously: I have severe misgivings that your project
> needs a Design Revision. This is not what autonumbers are meant to do.
>
> All the best
>
> Tim F

 
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
Creating a registration table list based on an existing table ChuckW Microsoft Access Forms 3 16th Dec 2007 12:35 PM
Creating a registration table list based on an existing table ChuckW Microsoft Access Queries 0 12th Dec 2007 04:13 PM
Creating table based on existing table =?Utf-8?B?U3RldmUgVy4=?= Microsoft Access 9 19th Apr 2007 07:18 PM
Getting table creating SQL script from an Existing table in VS 2003 =?Utf-8?B?UGV0ZXI=?= Microsoft Dot NET 1 16th Feb 2004 02:11 AM
Creating a table in Access based on structure of existing table Microsoft C# .NET 1 20th Dec 2003 03:47 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:44 PM.