A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Record auto numbering



 
 
Thread Tools Display Modes
  #1  
Old February 23rd, 2010, 04:00 PM posted to microsoft.public.access
hondo
external usenet poster
 
Posts: 9
Default Record auto numbering

I suppose I shouldn't be concerned, but my record autonumbering jumped from
135 to 432,233 when I was trying to copy and paste common info. Any way to
reset? Access Rookie
  #2  
Old February 23rd, 2010, 04:19 PM posted to microsoft.public.access
Jerry Whittle
external usenet poster
 
Posts: 4,732
Default Record auto numbering

If the numbers don't have "meaning" nor need to be sequential, no problem.
Actually if they needed to be sequential or have meaing, there would be a
problem as autonumbers often aren't as you just found out.

Still that is quite a jump. Copying and pasting can be a problem. It's
better to import instead.

You could empty the table, like exporting to Excel, then do a compact and
repair. Next import the records back. But it really isn't worth the effort.
--
Jerry Whittle, Microsoft Access MVP
Light. Strong. Cheap. Pick two. Keith Bontrager - Bicycle Builder.


"Hondo" wrote:

I suppose I shouldn't be concerned, but my record autonumbering jumped from
135 to 432,233 when I was trying to copy and paste common info. Any way to
reset? Access Rookie

  #3  
Old February 23rd, 2010, 04:23 PM posted to microsoft.public.access
jero
external usenet poster
 
Posts: 6
Default Record auto numbering

Hello,
Something like :
Public Sub InitNumAuto(A_Table As String, NumAuto As String)
'Ex : InitNumAuto "Table1","Num"
Dim Rst As DAO.Recordset, SqlStr As String
On Error Resume Next
SqlStr = "SELECT * FROM " & A_Table
Set Rst = CurrentDb.OpenRecordset(SqlStr)
With Rst
' Delete all records
.MoveFirst
Do Until .EOF
.Edit
.Delete
.MoveNext
Loop
' Update field "AutoNumber"
.AddNew
.Fields(NumAuto) = 0 'To start at 1, 99 to start at 100, ...
.Update
' Delete first record
.MoveFirst
.Edit
.Delete
.Update
.Close
End With
Set Rst = Nothing
End Sub
Bye
"Hondo" a écrit dans le message de news:
...
I suppose I shouldn't be concerned, but my record autonumbering jumped from
135 to 432,233 when I was trying to copy and paste common info. Any way
to
reset? Access Rookie



  #4  
Old February 23rd, 2010, 04:28 PM posted to microsoft.public.access
John W. Vinson
external usenet poster
 
Posts: 18,261
Default Record auto numbering

On Tue, 23 Feb 2010 08:00:01 -0800, Hondo
wrote:

I suppose I shouldn't be concerned, but my record autonumbering jumped from
135 to 432,233 when I was trying to copy and paste common info. Any way to
reset? Access Rookie


Don't bother.

Autonumbers have one purpose, and one purpose only: to provide a meaningless
unique identifier for a record. They'll always have gaps. They have a range up
to two billion odd (2^31 - 1) and will then pick up at negative two billion
odd and count up toward zero.

Copy and paste can introduce large gaps, as you have seen; for this and for
other reasons, it's often preferable to use Append queries or other techniques
to add new records. Where are you copying and pasting from?

For what it's worth, the only way to get back to gapless sequential numbers is
to create a new table, with an autonumber ID; and run an Append query
appending all the fields except for the ID. If your table is related to other
tables this can get complicated because you'll need to be sure that the
records link up.
--

John W. Vinson [MVP]
  #5  
Old February 23rd, 2010, 05:37 PM posted to microsoft.public.access
John W. Vinson
external usenet poster
 
Posts: 18,261
Default Record auto numbering

On Tue, 23 Feb 2010 17:23:18 +0100, "jero" wrote:

Hello,
Something like :
Public Sub InitNumAuto(A_Table As String, NumAuto As String)
'Ex : InitNumAuto "Table1","Num"
Dim Rst As DAO.Recordset, SqlStr As String
On Error Resume Next
SqlStr = "SELECT * FROM " & A_Table
Set Rst = CurrentDb.OpenRecordset(SqlStr)
With Rst
' Delete all records
.MoveFirst
Do Until .EOF
.Edit
.Delete
.MoveNext
Loop
' Update field "AutoNumber"
.AddNew
.Fields(NumAuto) = 0 'To start at 1, 99 to start at 100, ...
.Update
' Delete first record
.MoveFirst
.Edit
.Delete
.Update
.Close
End With
Set Rst = Nothing
End Sub
By


Hondo, just note that Jero's code will a) completely destroy all the data
currently in your table and b) will fail since Autonumber fields are not
updateable.
--

John W. Vinson [MVP]
  #6  
Old February 23rd, 2010, 06:15 PM posted to microsoft.public.access
Jeff Boyce
external usenet poster
 
Posts: 8,621
Default Record auto numbering

Why does this matter?

Who's looking at the Autonumbers?

Regards

Jeff Boyce
Microsoft Access MVP

--
Disclaimer: This author may have received products and services mentioned
in this post. Mention and/or description of a product or service herein
does not constitute endorsement thereof.

Any code or pseudocode included in this post is offered "as is", with no
guarantee as to suitability.

You can thank the FTC of the USA for making this disclaimer
possible/necessary.

"Hondo" wrote in message
news
I suppose I shouldn't be concerned, but my record autonumbering jumped from
135 to 432,233 when I was trying to copy and paste common info. Any way
to
reset? Access Rookie



  #7  
Old March 13th, 2010, 06:04 PM posted to microsoft.public.access
De Jager
external usenet poster
 
Posts: 393
Default Record auto numbering


"Jeff Boyce" wrote in message
...
Why does this matter?

Who's looking at the Autonumbers?

Regards

Jeff Boyce
Microsoft Access MVP

--
Disclaimer: This author may have received products and services mentioned
in this post. Mention and/or description of a product or service herein
does not constitute endorsement thereof.

Any code or pseudocode included in this post is offered "as is", with no
guarantee as to suitability.

You can thank the FTC of the USA for making this disclaimer
possible/necessary.

"Hondo" wrote in message
news
I suppose I shouldn't be concerned, but my record autonumbering jumped
from
135 to 432,233 when I was trying to copy and paste common info. Any way
to
reset? Access Rookie




 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 04:25 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.