Auitomatically save record

J

John Conklin

Hello all,

I need some help with saving a record.

I have a form for users to add new records to our database. We have about
30 users currently using this application and at times run into problems
when two or more people are trying to add records, causing the record to be
corrupted.

So, I created a new form for adding records, and want to be able to
automatically save that record to the table so if another user is trying to
add a new record it will pull the next id number and not the one the other
user is currently adding.

I have code behind my form that pulls the Max + 1 of the id number for the
current issue, and if two people try to add a record at the same time they
will get the same id number.

Can I make access automatically write this record to the table so that if
another user tries to add a record he gets the next number?

Thanks in advance for your help,
~John Conklin
 
G

Guest

hi,
I think you have a strategy problem.
you are calculating the next number.
so when two user are adding a new record they got the next
number based on the last number in the table which may be
the same if neither has add their record.
what i might suggest is create a small table with the next
number in it. when someone creates a new record, they get
the next number from the table and then have code
automaticly add one to the number when it was selected for
the next new record. that way the next user would be the
next number. this is more like autonumber and it would run
the risk of breaking the sequence if one user decides not
to add their record but with 30 users you don't seem to
have a lot of options.
you might look up record locks in help.
anyway thats my idea of a solution.
 
L

Lynn Trapp

Joseph Meehan's suggestion is probably the best way to go. Also, your issue
may simply be a timing problem. When are you getting the next number? Do you
do that when the user moves to a new record or when the record is being
saved? If you do it when the record is being saved -- i.e. in the
BeforeUpdate event of the data entry form -- then you are much less likely
to run into crashes.
 
Top