The only time a key will be "reused" is if you delete the record with the
highest number. If that could happen then I suppose you will have to use a
counter table. However, in the case of the highest number being deleted I
don't see what difference it makes if another record takes its place, unless
the information in the deleted record has been printed or is otherwise part
of your systems, but in that case I don't see why you deleted it in the
first place.
I have to say it strikes me as a somewhat arbitrary decision that it all
must be in a single function. I frequently create my own functions for
actions that need to be performed in two places such as the After Update
event of a combo box and the Current event of a form. Otherwise I would
need to write the same code twice, and change it in both places if an update
is needed. Access doesn't care if it has to "leave" the original code for a
function call or error handling. If there is a performance difference it is
negligible. In the case of using the form's error event it will occur only
if there is a specific error; otherwise it is ignored. But that's up to
you.
BTW, the default value can be assigned in code as well as by way of a text
box Default Value property.
I am going to retract something I said before. I believe you need to use an
ADO recordset, as the example with the counter table shows, instead of DAO,
because of record locking. The counter table is locked when you run the
code, preventing other users from updating the table. I don't know if this
type of record locking is possible with DAO. This would have to be the
subject of another thread, unless somebody who knows the details of this is
watching this thread. With ADO you will need to assure the library
reference is available, as stated in the code example. I don't know if this
reference would need to be set or checked for each computer using the
program. Again, you may need to start another thread. Check the link about
references to find out more.