Hi,
Locking as keeping anyone else outside, or locking as in not allowing
modifications? In the latter case, here a possible setting that logically
lock/unlock given records.
Table to be locked: table1, primary key field, pk.
Table keeping the keys of the "locked" records, locks, with a single
key, lock.
Goal: if a record in table1 has its pk value in locks.lock, the record
should not be deleted, neither modified. So, to logically lock a record, we
will write its pk value into locks.lock, and to "unlock" the record, we will
just remove its value from locks.lock.
1- Make a data referential integrity from locks into table1 such that
locks.lock must be present in table1.pk. DO NO CASCADE the DELETE, neither
cascade update, but be sure to enforce the integrity.
Doing so, it would then be impossible to delete a record in table1
that is in locks. You cannot either modify the pk value in table1 if the pk
is in locks.lock. Half of the job is done.
2- Add the following CHECK constraint in table table1:
CHECK( NOT EXISTS( SELECT * FROM locks WHERE lock=pk) )
If you modify a field in table1, for a given record, we have its pk
value. Before the modification would be accepted, the CHECK constraint will
be evaluated. It will return false if the pk value is in locks.lock, which
is ok, since we want to protect the record against modifications, in that
case.
To add a CHECK constraint, you need Jet 4.0 and to use ADO (not DAO) like,
in the Immediate Debug Window:
CurrentProject.Connection.Execute "ALTER TABLE tableName ADD CONSTRAINT
constraintName CHECK( ... )"
The constraintName must be unique in the whole database. You can drop the
constraint with
CurrentProject.Connection.Execute "ALTER TABLE tableName DROP
CONSTRAINT constraintName"
There is no User Interface to handle the CHECK constraints, even if they are
quite powerful.
Hoping it may help,
Vanderghast, Access MVP