Solved

copy back a table with autonumber

Posted on 2014-04-19
6
391 Views
Last Modified: 2014-04-19
Dear Experts,

I have a table with autonumber as index, but I allow the user to delete records randomly.
After that, I want to restore the table with autonumber without skipping, so I thought I could export the table without the autonumber field, then insert it back to the original structure.  As I am trying to do that, I get "invalid argument" error, and does not work.
How can I get my table to refresh, and get the autonumber in order as if I am entering the data as new?
Please advise.
0
Comment
Question by:yballan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 29

Expert Comment

by:IrogSinta
ID: 40010834
What is your purpose in re-sequencing the autonumber field?  That would be very inefficient to do every time a record is deleted.

Ron
0
 

Author Comment

by:yballan
ID: 40010840
More information:
In attempt to troubleshoot my query, I trimmed it down to just inserting one field, then I got a different error, looking for a mdb file.
But I am using Access 2010, my files are called XXX.accdb, and it is stored in a totally different folder from what the error message says.
I am extremely puzzled, please advise.
Untitled.jpg
0
 

Author Comment

by:yballan
ID: 40010843
Dear IrogSinta,

Thank you for your quick reply, I use the index for traversing forward and backward, and I find it easier to link everything if autonumbered index is in order.
This is meant to be as refreshing the table, and not supposed to happen often.
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 48

Assisted Solution

by:Dale Fye (Access MVP)
Dale Fye (Access MVP) earned 250 total points
ID: 40010851
I'm with IrogSinta,

Autonumber fields are meant to be used as primary keys and should be irrelevant to users as they should never even be visible to users.  

Indexing and traversing forward and backwards through the recordset has nothing to do with skipped values in the autonumber field.

Linking to that table will be a nightmare if you allow changes to the autonumber field and will likely break references to other tables.

I never resequence an autonumber field except when I first deploy an application, and then only after deleting all of the records in the table that were created during development and testing.  And only then for tables which are not used as lookup tables for use in my combo boxes and such.
0
 
LVL 29

Accepted Solution

by:
IrogSinta earned 250 total points
ID: 40010878
I will answer you're question on the problem with your Insert SQL statement question; however, this is just for your learning benefit and does not mean that you should continue down this erroneous path.  Fyed already gave you an excellent explanation on why you should not take that route.  It can definitely cause future problems.  Perhaps you should show us how you traverse your recordsets; you may be doing it wrong.

Here's the correction to your SQL:
INSERT INTO New Products (CategoryS) SELECT CategoryS FROM RefreshNewProduct

Open in new window

0
 

Author Closing Comment

by:yballan
ID: 40010886
Dear feyd and IrogSinta,

I appreciate your educating me for this error, I do realize that I am trying to force something that is not quite right.  I have inherited this large amount of code, and since I am short of time, I did not want to rewrite all of the traversing codes.  I understand that there is something fundamentally flawed with the design of the original code, and what I really should do is to understand it, and correct it.

Once I get through this deadline, I will rewrite this, I do believe that it will cause other problems as you said.
Thank you for the correct SQL script.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question