Unlock new records?

S

studlength

Hi. I have a form that I am trying to protect from accidental changes.
I used the code from Allen Browne's tip sheet "Locking bound controls"
at http://allenbrowne.com/ser-56.html. It works perfectly.

However, I would prefer each individual record to always stay locked
unless a user clicks on the cmdLock button. I would also like for the
record to lock back automatically when a user exits the record.

I accomplished this by putting the following line in the OnCurrent
property instead of the OnLoad property:
=LockBoundControls ([Form],True)
This works great, too.

Now to the problem. When a new record is created, it is automatically
locked. I would like for new records to be unlocked and stay unlocked
until the user exits it. Can someone please suggest how to do this?
 
P

pietlinden

Hi. I have a form that I am trying to protect from accidental changes.
I used the code from Allen Browne's tip sheet "Locking bound controls"
athttp://allenbrowne.com/ser-56.html. It works perfectly.

However, I would prefer each individual record to always stay locked
unless a user clicks on the cmdLock button. I would also like for the
record to lock back automatically when a user exits the record.

I accomplished this by putting the following line in the OnCurrent
property instead of the OnLoad property:
=LockBoundControls ([Form],True)
This works great, too.

Now to the problem. When a new record is created, it is automatically
locked. I would like for new records to be unlocked and stay unlocked
until the user exits it. Can someone please suggest how to do this?

use Me.NewRecord in the Form's OnCurrent event. Then just do
something like
LockBoundControls([Form], Not Me.NewRecord)

that way, if the record is new, the form is unlocked, and vice versa.
 
S

studlength

Thanks for your help. I'm not sure I understand what you're saying. I
am already using the OnCurrent event for the form. I tried replacing
what I have with:
LockBoundControls([Form], Not Me.NewRecord)
Access didn't like this.
Is there a way to modify Allen's code so the controls are only locked
if it is not a new record?
 
S

studlength

I worked on some other stuff for a while, came back to it and got it
working. I ended up selecting Event Procedure in the OnCurrent event
of the form. Then used the following code:

Private Sub Form_Current()
Call LockBoundControls(Me, Not Me.NewRecord)
End Sub

Works like a charm. Thanks again.
 

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