Chance! It took me 15 minutes to find this from an earlier thread I had posted! I've gotta get a grip on this search thing!...For your case use a long integer for the counter field. It won't handle strings = abcde...
I have run a table called tbldoctype.(Does other things as well). Includes An AutoID: "RefType", Description: (PO), (Bill of Lading) whatever, "Counter" which is the current number (default value of 1), "UseCounter" (True/False - set true for whatever you want to use it on). On your form new record command:
DoCmd.GoToRecord , , acNewRec
Me![NameOfYourNumberField] = NextNumber(1) '1 as example is the doctype number for "whatever you want to use it on".
Add this function to a public module:
Public Function NextNumber(RefType As Variant) As Variant
On Error GoTo ErrNN
Dim SQL1 As String, Rs As Recordset, Db as Database
Set Db = CurrentDb()
SQL1 = "SELECT tbldoctype.* FROM tbldoctype WHERE (((tbldoctype.RefType)= " & RefType & "

AND ((tbldoctype.UseCounter)=True))"
Set Rs = db.OpenRecordset(SQL1, dbOpenDynaset)
If Rs.RecordCount = 0 Then
Rs.Close
GoTo ErrNN
End If
NextNumber = Rs!Counter + 1
Rs.Edit
Rs!Counter = NextNumber
Rs.Update
Rs.Close
ExitNN:
Exit Function
ErrNN:
MsgBox Err.Number & " " & Err.Description, vbInformation, "Next document number generation error."
Resume ExitNN
End Function
There are other issues with this: Your user should first be asked if they really want to create the record, and they must not be able to delete it once set. In some cases I cannot do this and run a twin function called PreviousNumber which, you guessed it subtracts one from the count in the event of delete. (Copy the same function, rename and subtract 1 instead!). Now you can manage all your "document numbers" from one table and start them at any point you choose. Enjoy!
So Chance, take the 5 minutes required to build the "DocType" table, toss in some numbers and give it a go. This is your ticket!
Gord
ghubbell@total.net