Toggle Lock/Unlock Record on Form

G

Guest

Hi,

I want to add a toggle button to my form that when the button is depressed,
all fields on that record are locked. But when the toggle button is NOT
depressed, all the fields on that specific record are editable (i.e. will not
affect other records).

Does anyone know how to do this? I've been reading through some other
posts, but not solution is seeming to work for me. I tried putting the
If/Then Allow edits statement under Form On Current, but it didn't seem to be
doing anything for me. Anyone have some sage advice? Btw, the more detailed
the answer, the better. I'm obviously willing to work in VBA, but I'm a
newbie with it so you'll have to be gentle and explicit :)

Thanks for any help you can give!
 
G

Guest

Okay, I have an additional comment to add to this form. Apparently my code
IS working (the allow edit on current code). However, I do have one major
problem . . .

I used this suggestion someone posted for another question, and it seems to
do the job:
Perhaps you should add a field to your table called Locked (True/False).
When you want Lock a record, check Locked... or uncheck it to allow editing.
Now we can make a logical decision using the OnCurrent event of the form....
If Locked = True Then
Me.AllowEdits = False
Else
Me.AllowEdits = True
End If

And on the Locked AfterUpdate event...
If Locked = True Then
Me.AllowEdits = False
Else
Me.AllowEdits = True
End If


One problem persists. After I go to a new record, I'm no longer able to
UNCLICK the toggle button because it's now uneditable! Does anyone know how
to exclude one specific field from and allow edit statement?

Thanks!
 
R

Rick Brandt

StaceyJ said:
Okay, I have an additional comment to add to this form. Apparently my code
IS working (the allow edit on current code). However, I do have one major
problem . . .

I used this suggestion someone posted for another question, and it seems to
do the job:
Perhaps you should add a field to your table called Locked (True/False).
When you want Lock a record, check Locked... or uncheck it to allow editing.
Now we can make a logical decision using the OnCurrent event of the form....
If Locked = True Then
Me.AllowEdits = False
Else
Me.AllowEdits = True
End If

And on the Locked AfterUpdate event...
If Locked = True Then
Me.AllowEdits = False
Else
Me.AllowEdits = True
End If


One problem persists. After I go to a new record, I'm no longer able to
UNCLICK the toggle button because it's now uneditable! Does anyone know how

Exactly. The AllowEdits property applies to the *Form* not just the data, so it
is often more than what you want. What I do is enter a common Tag property
("Lock" for example), in all of the controls that I want to lock or unlock.
Then you can loop through the Controls collection and toggle the setting.

Dim cnt as Control

For Each cnt in Me
If cnt.Tag = "Lock" Then cnt.Locked = Me.ToggleButton
Next cnt
 
D

DebbieG

To fix the new record problem in Form_Current you could test for new record:

If me.newrecord than
Me.AllowEdits = True
end if

Test when you change records ... If you are using Next and Previous buttons
you can put your code in there.



| Okay, I have an additional comment to add to this form. Apparently my
code
| IS working (the allow edit on current code). However, I do have one major
| problem . . .
|
| I used this suggestion someone posted for another question, and it seems
to
| do the job:
| Perhaps you should add a field to your table called Locked (True/False).
| When you want Lock a record, check Locked... or uncheck it to allow
editing.
| Now we can make a logical decision using the OnCurrent event of the
form....
| If Locked = True Then
| Me.AllowEdits = False
| Else
| Me.AllowEdits = True
| End If
|
| And on the Locked AfterUpdate event...
| If Locked = True Then
| Me.AllowEdits = False
| Else
| Me.AllowEdits = True
| End If
|
|
| One problem persists. After I go to a new record, I'm no longer able to
| UNCLICK the toggle button because it's now uneditable! Does anyone know
how
| to exclude one specific field from and allow edit statement?
|
| Thanks!
|
| "StaceyJ" wrote:
|
| > Hi,
| >
| > I want to add a toggle button to my form that when the button is
depressed,
| > all fields on that record are locked. But when the toggle button is NOT
| > depressed, all the fields on that specific record are editable (i.e.
will not
| > affect other records).
| >
| > Does anyone know how to do this? I've been reading through some other
| > posts, but not solution is seeming to work for me. I tried putting the
| > If/Then Allow edits statement under Form On Current, but it didn't seem
to be
| > doing anything for me. Anyone have some sage advice? Btw, the more
detailed
| > the answer, the better. I'm obviously willing to work in VBA, but I'm a
| > newbie with it so you'll have to be gentle and explicit :)
| >
| > Thanks for any help you can give!
 

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