Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to start an autonumber field to Zero?

Status
Not open for further replies.

ayh8disjob

Programmer
May 31, 2001
41
0
0
SG
Hi! I need to distribute a database to another computer
how do i start all the autonumber field to zero and not 1?

Hope you could help me! Thanks in advance!

 
I dont think you can......autonumbers have to start at 1

You could write your own 'autonumber' system that starts at 0, or you could include an autonumber field and anotherfield that defaults to autonumber-1
 
If you are going to give them a copy of an empty database just compact the database and that will reset the autonumber to zero. At least it did for me when I did it.
Ellie
**Using Access 97**

lena.wood@wgint.com (work)
elliefant@starband.net (home)
 
Thanks guys! I think i already have the solution...
for your info to start an autonumber with 0 is not 1...

Create a module and enter this code:
Run this and after that compact the database.. thats it!


Sub Main()
Call sSetAutoNumber("Table1", "ID", 0)
End Sub
Function sSetAutoNumber(strTableName As String, strPKField As String, lngStartNumber As Long)
On Error GoTo E_Handle
Set db = CurrentDb
db.Execute "INSERT INTO [" & strTableName & "] ([" & strPKField & "]) VALUES(" & lngStartNumber - 1 & ");"
db.Execute "DELETE * FROM [" & strTableName & "];"
sExit:
On Error Resume Next
Set db = Nothing
Exit Function
E_Handle:
MsgBox Err.Description, vbOKOnly + vbCritical, "Error: " & Err.Number
Resume sExit
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top