lock specific distinct records

G

Guest

I need to be able to add an option for each record to lock it to prevent a
user from accidentially editing specific parts of it. For example each record
represents an invoice raised, but once sent certain fields (such as date and
amount) should not be edited or deleted. How can I do this?

Ideally I would like to add a "Lock" switch on the form so that I can always
turn this feature on or off with respect to this specific record at the users
discression.
 
J

John Vinson

On Sun, 3 Apr 2005 11:03:02 -0700, "Hatchet Harry" <Hatchet
I need to be able to add an option for each record to lock it to prevent a
user from accidentially editing specific parts of it. For example each record
represents an invoice raised, but once sent certain fields (such as date and
amount) should not be edited or deleted. How can I do this?

Ideally I would like to add a "Lock" switch on the form so that I can always
turn this feature on or off with respect to this specific record at the users
discression.

It's not too hard to do this on a Form: have a yes/no field, Lock, in
the table, and use the Form's BeforeUpdate event to cancel the update
if the record is marked locked. E.g.

Private Sub Form_BeforeUpdate(Cancel as Integer)
If Me.Lock Then
MsgBox "This record is locked for editing", vbOKOnly
Cancel = True
End If
End Sub

Or, you can put similar code in the BeforeUpdate event of each control
which should be frozen; or, even better, use the Form's Current event
to lock individual controls:

Private Sub Form_Current()
If Me.Lock Then
Me!txtInvoiceDate.Enabled = False
Me!txtInvoiceDate.Locked = True
Me!txtInvoiceDate.BackColor = vbYellow ' visual indicator
Me!txtAmount.Enabled = False
Me!txtAmount.Locked = True
Me!txtAmount.BackColor = vbYellow
Else
<you get the idea>

However, this will not prevent a user from opening a query or table
datasheet and doing what they want. The only way to block that is to
invoke Access Security on the database and make your form the only
venue in which users can touch the data.

John W. Vinson[MVP]
 

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