default nember

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hello,

is there any kod wich will give us as default
the sequnt 'id' number of the 'id' number in the latest record ?

thank you,
 
???? ????? said:
is there any kod wich will give us as default
the sequnt 'id' number of the 'id' number in the latest record ?

If you are using AutoNumber for your unique ID, and not using Replication
IDs, then the DMAX function will return the highest value of that Field in
the Table. This is fine for a single user application, but not completely
reliable if you have multiple users, because two users might get the same
number for "most recent" (largest) and each then use it to create a new
record.

The reliable way for multiple users is to have a Table of Tables with the
next available ID along with the TableName. To prevent "collisions" use code
to retrieve and update that value inside a Transaction. In this case, the ID
field in the Table would be a Long Integer, not an AutoNumber.

Larry Linson
Microsoft Access MVP
 
Thank you larry,

The problem is that i dont use Autonumber but
number that the user puts by himself
and i want to help him to put the corect (sequent) number.
 
If you are using AutoNumber for your unique ID, and not using Replication
IDs, then the DMAX function will return the highest value of that Field in
the Table.

I don't this is a reliable approach e.g. a user can INSERT explicit
values into an autonumber column (hint: such a value could be
2,147,483,648). Also, non-ReplicationID autonumbers can be random as
well as incremental.

Microsoft advise that SELECT @@IDENTITY (use in ANSI-92 Query Mode)
should correctly return the last autonumber generated for the current
connection and should be reliable if you have multiple concurrent
users. See:

http://support.microsoft.com/default.aspx?scid=kb;en-us;232144
The reliable way for multiple users is to have a Table of Tables with the
next available ID along with the TableName. To prevent "collisions" use code
to retrieve and update that value inside a Transaction.

Sounds good! FWIW the full details of such an approach can be found in
the following Microsoft article:

http://support.microsoft.com/default.aspx?scid=kb;en-us;240317

Another approach is to have a table (one for each key) of pre-generated
key values and allocate them à la chequebook/checkbook.

Jamie.

--
 
a user can INSERT explicit
values into an autonumber column (hint: such a value could be
2,147,483,648)

Now that's just too excessive <g>. Try 2,147,483,647 instead.

Jamie.

--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top