Lock Record

G

Guest

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.
 
G

Guest

Locking a control will not dim it. To dim it, you will either have to use
the Enabled property or Lock it and change the back color (you could also use
a different color for the forecolor). The difference here is that a control
with the Enabled property set to False will not be included in the Tab Order,
but a locked control will.

You do not need the the Locked field. You mentioned Toggle buttons. That
is one way to do it, but another way would be with a command button. I will
give you an example using the command button. Put something like this in the
Click event:

If Me.cmdLock.Caption = "Lock" Then
Me.SomeControl.Locked = True
Me.AnotherControl.Locked = True
Me.cmdLock.Caption = "Unlock"
Else
Me.SomeControl.Locked = False
Me.AnotherControl.Locked = False
Me.cmdLock.Caption = "Lock"
End If

Make sure that the default Caption and Locked properties are set in design
mode so they are in sync when the form opens. For example, if the controls
Locked properties are set to Yes, then the Caption for the button should be
"Unlock"

And, if you want to avoid the hassle of listing each control on the form by
name, you can use the For Each loop to set the property:

Dim ctl As Control

For Each ctl in Me
If ctl.Type = acTextBox Or ctl.Type = acComboBox Then 'Add more types?
ctl.Locked =
End If
Next fld
 
G

Guest

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!
 
G

Guest

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.
 
G

Guest

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!
 
G

Guest

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.
 
G

Guest

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?
 
G

Guest

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")
 

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

Similar Threads

Access Form - Lock Fields from Editing 0
Lock 1
lock individual fields in access form 1
how to lock a form and subforms 2
conditional field lock 5
Lock a form 3
lock scroll to input data 1
Lock and unlock records 1

Top