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
Microsoft Access
Last Comment
Rey Obrero (Capricorn1)
8/22/2022 - Mon
Rey Obrero (Capricorn1)
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
SteveL13
ASKER
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)
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
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
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
private sub .chkbxFormLocked_afterupda
dim ctl as control
for each ctl in me.controls
if ctl.controltype<>aclabel then
if ctl.name<>".chkbxFormLocke
ctl.locked=me.chkbxFormLoc
end if
end if
next
end sub
next