Autonumber Already Exists

T

Tom

All,

Anybody ever see an autonumber in a small table (<3000 records) create
an autonumber out of sequence? I can't add a new record without
getting an error message that the primary key autonumber already
exists (which it does). Help!
 
G

Golfinray

Yes. Autonumbers are primariy for the purpose of joining tables, they are not
necessarily sequential, and are NOT designed to be record numbers. If you
want actual record numbers, I think Allen Browne has a tip on that at his
site, www.allenbrowne.com
 
T

Tom

Sorry if I'm not being clear...I don't need a record number, nor do I
need it to be sequential. I simply need an autonumber, which happens
to be the primary key of this particular table, to act like an
autonumber is supposed to and NOT repeat itself.

I found the following KB article, which I'm digesting now:
http://support.microsoft.com/kb/884185

--Tom
 
T

Tom

The KB article below allowed me to "re-seed" the autonumber field.
All is well now.

Note: The SQL-specific re-seed query workaround referenced in the KB
article did not mention that it couldn't be used on linked tables. To
use it, I had to create the temporary query directly in the back end
database on the server.

Hope this helps someone else in the future,

Tom
 
V

vasco

Tom said:
All,

Anybody ever see an autonumber in a small table (<3000 records) create
an autonumber out of sequence? I can't add a new record without
getting an error message that the primary key autonumber already
exists (which it does). Help!

I see that some years ago and I use:

Private sub Form_BeforeInsert(Cancer As Integer)
If DCount("MyField" , "MyTable") = 0 Then
me.MyField = 1
Else
me.MyField = DMax("MyField" , "MyTable") + 1
End If
End Sub
 
J

John W. Vinson

I see that some years ago and I use:

Private sub Form_BeforeInsert(Cancer As Integer)
If DCount("MyField" , "MyTable") = 0 Then
me.MyField = 1
Else
me.MyField = DMax("MyField" , "MyTable") + 1
End If
End Sub

Similar logic but simpler:

Private Sub Form_BeforeInsert(Cancel as Integer)
Me.MyField = NZ(DMax("[MyField]", "[MyTable]")) + 1
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top