Hey Vito,
I came upon the same issue a few months ago. I want to give you a little something to consider. Is this a table that will be accessed by more than one user at a time? (Mine is.) The problem that comes up is this:
The last record was #17.
User A starts to create a new record. The function checks the last record and determines that the next record will be #18.
User B starts to create a new record. The function checks the last record and determines that the next record will be #18.
User A saves their record, #18.
User B saves their record, #18, and gets a conflict.
If there is only one user, no problem. But if you have a multi-user environment, you'll need to take extra precautions.
Here is a code snippet that might help:
Code:
Dim numNewRec As Double
' Determine the new record number.
' Add 1 to the highest Rec_Num in the database.
numNewRec = DMax("Rec_Num", "Main")+ 1
RecNum.Value = numNewRec
I use Double because my Record Numbers are 8 digits. RecNum is a control on my New Record form. I populate the control with the new record number at the beginning of the Save button Click subroutine. It is immediately written into the Main table so that there is virtually no time for a second user to claim the same new Record Number. A couple of milliseconds, maybe, but not enough to worry about.
HTH,
Marvin M