Solved

copy back a table with autonumber

Posted on 2014-04-19
6
389 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 47

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

739 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