Lock Record

N

nraczyk

I would like to use a toggle button on a form to lock, and dim, data (on an
individual record basis) after entry, but reserve option to un-toggle the
lock to update data, if necessary. I've tried to follow other examples, but
I get errors that I don't know how to fix.

This is what I have already:
- a form named "Property Checklist"
- a field, bound to the form, (Yes/No) labeled "Lock"

Any advice is greatly appreciated!
 
W

Wayne Morgan

In the button's Click event:

Example:
'Make this a toggle, we can't use the checkbox to click on because that
would be an
'edit, which is something we're preventing.
If Me.AllowEdits = True Then
Me.chkLocked = True
'Save all current changes
Me.Dirty = False
Me.AllowEdits = False
Else
Me.AllowEdits = True
Me.chkLocked = False
'Save the setting change
Me.Dirty = False
End If

This will set the field to true to indicate that the record should be
considered "locked". By setting the form's AllowEdits to false, it won't
allow you to edit the record. The next step is to have the value in the
field checked as you move from record to record. To do this, use the form's
Current event.

Example:
Me.AllowEdits = Not Me.chkLocked

This will set AllowEdits to the opposite of the value of the chkLocked
checkbox. For example, if the checkbox is checked (True) then AllowEdits
will be False.
 
N

nraczyk

Unfortunately, I'm still having troubles.

I really would like to 'disable' ALL controls for THAT record once the
toggle is depressed; I've been getting the entire form to lock; and Tab Order
is not priority.

Specifically,

IF ToggleButton is depressed, THEN Enable = False for all controls; and I
have over 50 controls, which would be tedious to list them all!

My understanding of this code stuff is very limited, but developing this
event will be very helpful.

thanks again!
 
K

Klatuu

Okay, then see my previous post describing the For Each loop. You will not
want to disable labels or command buttons, however, so exclude them from the
list.
 
N

nraczyk

Thanks ... but I'm not quite there yet - I'm getting an error at:

ctl.Locked =

and if I set the above to equal True or False, I then get an error at:

Next fld

Please review the code for any missing language. Thanks again!
 
K

Klatuu

Sorry, the code was untested air code and I made an error. It should be Next
ctl
and yes, you must set ctl.Locked = True or False, depending on what you want.
 
N

nraczyk

OK ... this is my last shot - otherwise I'll just write out all the controls.

This is the code I have:

--------------------------------------------
Private Sub lockbox_Click()

If Me.lockbox.Caption = "Lock" Then
Me.lockbox.Caption = "Unlock"
Else
Me.lockbox.Caption = "Lock"
End If

Dim ctl As Control

For Each ctl In Me
If ctl.Type = acTextBox Or ctl.Type = acListBox Then
ctl.Enabled = True
End If
Next ctl


End Sub

--------------------------------------


But now I'm getting a different error:

Run-time error '438':
Object doesn't support this property or method.



Any thoughts?
 
K

Klatuu

Private Sub lockbox_Click()
Dim ctl As Control
dim blnLock as Boolean

blnLock = Me.lockbox.Caption = "Unlock"
For Each ctl In Me
If ctl.Type = acTextBox Or ctl.Type = acListBox Then
ctl.Enabled = blnLock
End If
Next ctl
Me.lockbox.Caption = Iif(blnLock,"Lock", "Unlock")
 
Top