multiple user - generate number

J

jberiksen

I have a Access database used by more users, where each new record get a
number that 1 higer than the last number.

But my problem is that when a user make a record, and then another user make
a record within the first user have finished the work with his record, the
second user get a number that's 0. Then the second user have to wait to the
first is finish, within he can make his record.

Someone how can help me with som code that can solve thet problem



The code I use today to genetate the number is:

Private Sub Form_Current()
If Me.NewRecord Then
Me.Sagsnummer = DMax("Sagsnummer", "Sager") + 1
End If
End Sub
 
E

ErezM via AccessMonster.com

hello
first, i think it's better to use BeforeInsert event of the form (you dont
have to check for NewRecord there...).
for the unique key number, one solution can be to save the record immediately
after BeforeInsert is launched, then the user is actually updating an
existing record, instead of adding a new one.
then the next user that will try to add, will get the next higher number
(because the table cannot have 2 "NewRecords", the first must become "old" to
free the NewRecord "slot")

the drawback of this method is that you need to take care for unwanted new
records (because they are already saved to the table)

good luck
Erez
 
R

Rick Brandt

I have a Access database used by more users, where each new record get a
number that 1 higer than the last number.

But my problem is that when a user make a record, and then another user
make a record within the first user have finished the work with his
record, the second user get a number that's 0. Then the second user have
to wait to the first is finish, within he can make his record.

Someone how can help me with som code that can solve thet problem



The code I use today to genetate the number is:

Private Sub Form_Current()
If Me.NewRecord Then
Me.Sagsnummer = DMax("Sagsnummer", "Sager") + 1 End If
End Sub

Use BeforeUpdate event instead. This is the only event that ends with
the record being saved. That means only fractions of a second between
calculating the value for your record and committing it to the table so
the next person will see it and go one higher.
 
J

jberiksen

Can you write the cod i have to past in BeforeInsert and AfterInsert, I can't
get it working
hello
first, i think it's better to use BeforeInsert event of the form (you dont
have to check for NewRecord there...).
for the unique key number, one solution can be to save the record immediately
after BeforeInsert is launched, then the user is actually updating an
existing record, instead of adding a new one.
then the next user that will try to add, will get the next higher number
(because the table cannot have 2 "NewRecords", the first must become "old" to
free the NewRecord "slot")

the drawback of this method is that you need to take care for unwanted new
records (because they are already saved to the table)

good luck
Erez
I have a Access database used by more users, where each new record get a
number that 1 higer than the last number.
[quoted text clipped - 13 lines]
End If
End Sub
 

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

Top