Full Version: Custom Auto Numbers
UtterAccess Discussion Forums > Microsoft® Access > Access Forms
AfCo
I want to create an auto number, but I want it to start with a number I tell it to. For example...

First number is 1110, then I want it to automatically assign 1111, 1112, 1113 etc... for each new record. Is there a way to do this?

Thanks!
balaji
Try this link.
Alan_G
Or another method.........

you could have a text box on your form and use something like

Me.MyTextBox = Nz(DMax("MyNumberField","MyTable"),1110) + 1

in whatever event suits your needs
jmcwk
CODE
Private Sub Form_Current()

  If Me.NewRecord Then

    On Error Resume Next 'It should never occur, just to be sure...

    Me!MyTextBox.DefaultValue = Nz(DMax("[MyTextBox]", "MyTable"), 1110) + 1

  End If

End Sub


Edited by: jmcwk on Thu Dec 7 16:21:36 EST 2006.
balaji
Also, if you just want to use the autonumbering capability provided by Access,but want the autonumber to start at 1111 instead of at 1, do the following:

1. add dummy records to the table until autonumber reaches 1110
2. add record that should have ID 1111
3. delete all dummy records

Note that an autonumber field does not guarantee that the numbering will be contiguous. Autonumber fields will skip numbers that were assigned to records that were added and then subsequently deleted. Read the information in this link to understand what autonumbers are and what they are not.
AfCo
Well I tried the code on the link and all I got was 0 in the field, then I tried the code posted by jmcwk and it came up with the same thing. Only reason why I don't want to go the route of creatingthe dummy records is because it would be very time consuming. Am I doing something wrong?!?
jmcwk
Afco,

see if the attached is what you need. Look at the code behind the On current event of the Form frmNumber and to see it work go to a new record and enter a name. As you can see from the code the Nbr was started at 1110 + 1 so the first record is 1111 etc.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.