Locking a record

T

Tony F

I have created a database in Access 2000 and I wish to lock records using a
checkbox on a form. After reading previous questions & answers I tried the
following code in the checkbox's after update event.

Private Sub APPROVED_AfterUpdate()
If chkApproved = True Then
Me.AllowEdits = False
Me.AllowDeletions = False
Else
Me.AllowEdits = True
Me.AllowDeletions = True
End If
End Sub

"Approved" being the checkbox.
The equivalent code is also in the form's OnCurrent event.
It's not working, I can still edit the record via the form.

Can you tell me what else I need to do.

Thanks in advance.
 
A

Allen Browne

When you check the Approved box, the record is dirty (needs to be saved.) If
Microsoft allowed your code to work, you would now be stuck: unable to
complete the edit, unable to undo, just stuck.

They guessed we would do this to ourselves, and so the change to AllowEdits
does not get applied until after you save the record. You should find that
if you save (e.g. press Shift + Enter), the form is now uneditable.

If that is not the case, there's a good chance that you have some other code
that is dirtying the form again (e.g. in the AfterUpdate event of the form,
or its Current event.) The icon in the form's Record Selector will be a
pencil if edits are on progress. (Show the Record Selector, at least for
debugging purposes.)

There are also some other potential logical problems here:

a) The form will remain uneditable even if the user undoes the entry instead
of saving it. You need to use the form's Undo event to address that.

b) Once you get it all working, the Else part can't work, because the user
can't edit it.

c) The code is in an event for a control named APPROVED, but you are
checking the value of chkApproved. (Not sure if that's intended.)
 

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