Hi Jacqueline
If your account number is a simple numeric value (long integer), you can
generate the next one by using the DMax function and incrementing the
value
returned. In case there is no record already there, you can throw in an
Nz
function to give you a starting value:
NewAccNum = Nz( DMax( "[AccountNum]", "YourTable" ), 0 ) + 1
If you have a busy multi-user environment, it is possible using this
technique to have the same number allocated twice, if two users are
adding
an account at the same time and the second one starts before the first
has
saved the new record. In this case you must either (a) handle the
problem
when it occurs by generating a new number and alerting the user that it
has
changed or (b) by having a special "NextAccount" table which you open for
exclusive access, retrieve the value, increment the stored value, and
write
it back to the table.
In practice, these precautions are rarely necessary, so post back if you
are
interested in further details.
--
Good Luck
Graham Mandeno [Access MVP]
Auckland, New Zealand
Ken,
Thanks this makes sense. Now, can you tell me where I could look for
code
as
examples? I am a strong Access user, but not so good with Visual Basic.
If
I
have code to look at and play with I usally can figure out what I need.
Thanks again,
--
Jacqueline Staley
:
While an AutoNumber field can be used to auto-create incrementing
numbers,
it's not a good approach if you don't want gaps between the numbers,
and
if
you don't want negative numbers as the result.
It's best to write your own procedure to auto-increment values for
this
purpose. An easy one is to find the current, maximum value for the
field
in
the table, and then increment that value by one, and then assign that
value
as the new number.
--
Ken Snell
<MS ACCESS MVP>
Access 2003 question:
Does anyone know how to set up an automatic account number
generation
in
Access? I suspect that it can be done with the Auto number, but not
sure
how
to do this to allow for a never ending amount of accounts.
Is there an add-in or secondary add-in that can do this? I would
like
to
incorporate the date into the account number if possible.
I am construction a new database that formally did not have account
numbers
attached, the client was using the address ast the PK....
Any help will be greatly appreciated.
Thanks