How lock form with checkbox but be able to unlock the form with the same checkbox

I have a checkbox on a form labeled "Lock Record".  The user will use this checkbox to lock the data on the form so users can't change anything.  I'm trying the following code  which doesn't work because obviously the checkbox is locked so the user can't UNlock the data which they need to be able to do.  There must be a better way/

    If Me.chkbxFormLocked = True Then
        Me.AllowAdditions = False
        Me.AllowDeletions = False
        Me.AllowEdits = False
        Me.cmdAddRecord.Enabled = False
        Me.chkbxFormLocked.Enabled = True
    End If
SteveL13Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rey Obrero (Capricorn1)Commented:
use the afterupdate  or change event ofthe checkbox

private sub .chkbxFormLocked_afterupdate()
dim ctl as control
for each ctl in me.controls
     if ctl.controltype<>aclabel then
         if ctl.name<>".chkbxFormLocked" then
             ctl.locked=me.chkbxFormLocked
         end if
      end if
next
end sub
next
SteveL13Author Commented:
Getting an error on

ctl.locked=me.chkbxFormLocked

"Object doesn't support this property or method"

Also had to comment out:
'end sub
'next
Rey Obrero (Capricorn1)Commented:
private sub .chkbxFormLocked_afterupdate()
dim ctl as control
for each ctl in me.controls
     if ctl.controltype<>aclabel then
         if ctl.name<>"chkbxFormLocked" then
             ctl.locked=me.chkbxFormLocked.value
         end if
      end if
next
end sub
Your Guide to Achieving IT Business Success

The IT Service Excellence Tool Kit has best practices to keep your clients happy and business booming. Inside, you’ll find everything you need to increase client satisfaction and retention, become more competitive, and increase your overall success.

SteveL13Author Commented:
Same error on

ctl.Locked = Me.chkbxFormLocked.Value
Rey Obrero (Capricorn1)Commented:
private sub chkbxFormLocked_afterupdate()
dim ctl as control

for each ctl in me.controls
     if ctl.controltype<>aclabel then
         if ctl.name<>"chkbxFormLocked" then
             me(ctl.name).locked=me.chkbxFormLocked.value
         end if
      end if
next
end sub
SteveL13Author Commented:
Same error using:

Me(ctl.Name).Locked = Me.chkbxFormLocked.Value
Rey Obrero (Capricorn1)Commented:
do a compact and repair and the do a Debug>compile

correct any errors raised

if that doesn't fix it, your form could be corrupted.

create a new form and try the codes again.
SteveL13Author Commented:
Compiled.  C&R.  Copied objects to new form.  I'm now trying this ans still get the error "Object doesn't support this property or method"

Dim ctl As Control

    If Me.chkbxFormLocked = True Then
    For Each ctl In Me.Form.Controls
        Me(ctl.Name).Locked = True
    Next
    End If

Open in new window

Rey Obrero (Capricorn1)Commented:
this is not my code
 For Each ctl In Me.Form.Controls

the code I posted is
 For Each ctl In Me.Controls


and I tried it over and over again and it is working....
COACHMAN99Commented:
if ray's comment doesn't fix it then its possible one of the controls in the collection doesn't support the locked property.
add a msgbox ctl.name line so you can identify which one, then only set locked  'if ctl.name <> problem one,

e.g.
    If Me.chkbxFormLocked = True Then
    For Each ctl In Me.Controls
      msgbox ctl.name
        Me(ctl.Name).Locked = True
    Next
    End If

and once you know which one causes the error

    If Me.chkbxFormLocked = True Then
    For Each ctl In Me.Controls
      if ctl.name <> 'whatever' then Me(ctl.Name).Locked = True
    Next
    End If
Rey Obrero (Capricorn1)Commented:
one more time.. copy everything, do not make shortcut.

private sub chkbxFormLocked_afterupdate()
 dim ctl as control

 for each ctl in me.controls
  if ctl.name<>"chkbxFormLocked" then
    If ctl.ControlType = acTextBox _
        Or ctl.ControlType = acComboBox _
        Or ctl.ControlType = acCheckBox _
        Or ctl.ControlType = acListBox Then
        ctl.Locked = me.chkbxFormLocked.value
    end If
 end if
 next
 end sub

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.