Writing new record data immediately to table

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

Guest

My database works in a multiuser environment where different people may
create simustaneously records to be written to the same table. It happens
that if one person creates a record and fills in data, another person
sometimes overwrites that record while creating her own a few minutes later
if the first record has not been written to the table.

So I have to ensure that while a new record is created, the initial data,
especially the primary key, is written directly to the table so that the next
user creating a record picks indeed a new record.

I have written a DoCmd.Requery statement in the forms Current procedure, but
I wonder if there is a neater way of doing this.
 
Bakema,

Consider using an Autonumber for your Primary Key. It is specifically
designed to avoid the kind of data conflict you describe.

However, there are legitimate times when you can't use Autonumber. In
this case, when you add a new record, you must:
* Generate a new, unique key
* Set the key field in the record to the new value

This is most easily done with a separate table that holds one record
with the latest key. Your code reads the key, generates the next value,
and saves it back to the table. The new value can now safely be used in
your main table. One note: don't worry about skipped key values! This
behavior is vital to avoid duplicates.

You can do this in the Form_Current event. Simply check the NewRecord
property, and if true, create your new key and set the key field value.
Me.Requery is not needed.

-Ken
 
Back
Top