473,379 Members | 1,386 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Table Auto Number Problems

I have a table that has the field "ID" set to auto number and also set as the primary key. Whenever I delete a record then go to add one, it will not re use the ID of the record I deleted. In other words say I have 125 records and I delete number 74, when I add a record instead of it giving the ID 74 it gives it the ID of 126. I need this to keep a certain number so is there a way around this? THANKS!!
Feb 12 '07 #1
7 2387
maxamis4
295 Expert 100+
There are two fixes that I know of for this problem.

1. One create an exact copy of the table you have and only copy the structure not the data. Then append the data into this table and the count will restart. Use an append query to do this, only the data should be copied. Auto number is a stored procedure in access that was designed to account for unique controls that the database needed.

2. Setup your auto number programmatically using a module.

is auto number your unique ID???


if so you could lose realtionships with other tables.
Feb 12 '07 #2
NO the ID is just there to keep track of how many records there are. And as for the first solution, I never use access and have no idea what you said, enlighten me.
Feb 13 '07 #3
maxamis4
295 Expert 100+
1. For the first part what you want to do is right click on your table and select copy
2. Then you will have an option to copy data and structure or just structure. Select "The Just Structure option" This should give you an empty shell with no data but all the same fields you used. Make sure you name the table "Your Table Name-2".
3. Then go to queries.
4. Click on the "Create query in Design view" option
5. Select "Your Table Name" where your data is current stored.
6. Click Add and then go to query type in the top tool bar next to the red exclamation mark. It will be an icon that looks like two tables on top of each other. Select Append query from there, and it will ask you which table you want to append too. Select "Your Table Name-2" and click okay
7. Once this is done drag in drop all the fields except for your auto number field.
8. Finally click on the red exclamtion mark and say yes to all the defaults that it ask.

9. Verify that your data and your auto number are okay, and delete your old "Your table name" then rename your old "Your table name-2" to the deleted table.

Good luck

FYI programmatically would do you more justice than auto number
Feb 13 '07 #4
Rabbit
12,516 Expert Mod 8TB
If you just want to know how many records there are in the table there are other ways of doing that without storing it in the table. One way is:
DCount("*", "Table Name").
Feb 13 '07 #5
Well I tried doing that first step by appending the table but it still does the same thing. If I were going to do it programmatically would I do something like:

Count how many records there are>
For loop, adding numbers 1-how many records there are to the ID column on the table>
Feb 14 '07 #6
maxamis4
295 Expert 100+
As long as you appended everthing except the auto number into a new table that should have worked.

Programmatically I would create a function called increment
Expand|Select|Wrap|Line Numbers
  1. Public Function Increment() As Long
  2.  
  3. On Error GoTo NextID_Err
  4.  
  5. Dim lngNextID As Long
  6.  
  7.     'Find highest Employee ID in the tblPracticeEmployeeData table and add 1
  8.     lngNextID = DMax("[The Field you want to increment]", "Your Table") + 1 
  9.  
  10.     'Assign function the value of the Next ID
  11.     Increment = lngNextID
  12.  
  13.     'Exit function now after successful incrementing or after error message
  14. Exit_Increment:
  15. Exit Function
  16.  
  17.     'If an error occurred, display a message, then go to Exit statement 
  18. NextID_Err:
  19.     MsgBox "Error " & Err & ": " & Error$
  20.  
  21.     Resume Exit_Increment
  22.  
  23. End Function
  24.  
set a button to call this or you can do it to trigger on new records. Your choice
Feb 14 '07 #7
This is how I ended up doing it. Thanks for the help.

Expand|Select|Wrap|Line Numbers
  1. Dim db As DAO.Database
  2. Dim rs1 As DAO.Recordset
  3.  
  4.  
  5.   Set db = CurrentDb() 
  6.   Set rs1 = db.OpenRecordset("Query1") 
  7.  
  8.  
  9.   rs1.MoveFirst 
  10.   i=1
  11.   Do Until rs1.EOF
  12.  
  13.     rs1.Edit
  14.     rs1![ID] = i
  15.     rs1.Update
  16.     i=i+1
  17.     rs1.MoveNext
  18.   Loop
Feb 15 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Dragon | last post by:
When I run a make-table query, the results take over 1 minute to return. The query is making a table that has 12,000 records in it. If I run the make-table query ONLY to see the records that will...
5
by: JonH | last post by:
Ok, I have this dynamically created table in my one of my php forms that shows the names of the people the user has entered into a text field. When they hit add a row displays, showing the name...
2
by: Greg Strong | last post by:
Hello All, Is it possible to change table field lookup properties in code? I've been able to change other field properties in code, however so far no luck with field lookup properties. What...
21
by: Johan Tibell | last post by:
I would be grateful if someone had a minute or two to review my hash table implementation. It's not yet commented but hopefully it's short and idiomatic enough to be readable. Some of the code...
1
by: daniellee2006 | last post by:
I am creating a basic website to store people profiles and within this website i have a page that creates a table dependent on the number of records in mysql written in PHP within these tables...
6
by: McKirahan | last post by:
I an using ASP to read a database table and generate an HTML table which is save via FSO with a file extension of .xls which opens up in MS-Excel. I am inserting several lines of text into a cell...
6
by: Romulo NF | last post by:
Greetings again to everyone, Im back to show this grid componenet i´ve developed. With this grid you can show the data like a normal table, remove the rows that you need, add rows, import data,...
23
by: raylopez99 | last post by:
A quick sanity check, and I think I am correct, but just to make sure: if you have a bunch of objects that are very much like one another you can uniquely track them simply by using an ArrayList...
5
by: Stepheno | last post by:
Hi, I am a recently converted Iseries (AS/400) RPG programmer trying to learn HTML/CSS/JavsScript all at the same time (not fun). My problem deals mostly with CSS. I will be reveiving a table,...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.