Allowing/locking edit in a form

helent24

Registered User.
Local time
Tomorrow, 09:35
Joined
Jan 22, 2009
Messages
16
Hi All

I'm using Access 2003.

I'm trying to create a command for a form that will allow editing or lock all fields, so that records are protected from accidental edits.

AllowEdits in the form is set to False by default.

I've used the below code to allow a user to unlock the form:

Private Sub cmdEditRecord_Click()
If Me.AllowEdits = False Then
Me.AllowEdits = True
Else
Me.AllowEdits = True
End If
End Sub

And this works without issue.

However, I want to create a second button to lock the form again.

Private Sub cmdLockRecord_Click()
If Me.AllowEdits = True Then
Me.AllowEdits = False
Else
Me.AllowEdits = False
End If
End Sub

Seems logical that I should just be able to reverse the true/false but this does nothing! Any thoughts?

I've also tried the below code:

Private Sub cmdEditRecord_Click()
Me.AllowEdits = Not (Me.AllowEdits)
End Sub

To toggle between editing/locked, with the same results - ie, can switch to editing, but can't then turn it off.
 
Try using:

Private Sub cmdEditRecord_Click()
If Me.AllowEdits = False Then
Me.AllowEdits = True
end if

and


Private Sub cmdLockRecord_Click()
If Me.AllowEdits = True Then
Me.AllowEdits = False
End If
End Sub
 
Hi Drunkenneo

Same result with your code - cannot lock the record.

But I worked out a work around... using the below to lock the record when moving to a new one. In fact, this is probably more reliable, as I don't have to count on the user locking the form again.

Private Sub Form_Current()
If Me.AllowEdits = True Then
Me.AllowEdits = False
End If
End Sub

Why this identical code will work in some circumstances but not all is a mystery.

Thanks for your reply.
 
Using the Form_Current event to do this kind of thing is pretty standard, for the very reason you stated: you're not dependent on the user re-locking it.

And there's no need, in the Form_Current code, to use the If...Then construct; a simple

Me.AllowEdits = False

will do. The reason using it, as you originally did, didn't work, is because you have to Save the Current Record before setting AllowEdits back to False; you apparently cannot set AllowEdits back to False on a Dirty Record, which makes sense.

Linq :0)>
 
Last edited:
THanks, missinglinq, it's good to make some sense of why this wouldn't work.
 

Users who are viewing this thread

Back
Top Bottom