SteveL13
asked on
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
If Me.chkbxFormLocked = True Then
Me.AllowAdditions = False
Me.AllowDeletions = False
Me.AllowEdits = False
Me.cmdAddRecord.Enabled = False
Me.chkbxFormLocked.Enabled
End If
ASKER
Getting an error on
ctl.locked=me.chkbxFormLoc ked
"Object doesn't support this property or method"
Also had to comment out:
'end sub
'next
ctl.locked=me.chkbxFormLoc
"Object doesn't support this property or method"
Also had to comment out:
'end sub
'next
private sub .chkbxFormLocked_afterupda te()
dim ctl as control
for each ctl in me.controls
if ctl.controltype<>aclabel then
if ctl.name<>"chkbxFormLocked " then
ctl.locked=me.chkbxFormLoc ked.value
end if
end if
next
end sub
dim ctl as control
for each ctl in me.controls
if ctl.controltype<>aclabel then
if ctl.name<>"chkbxFormLocked
ctl.locked=me.chkbxFormLoc
end if
end if
next
end sub
ASKER
Same error on
ctl.Locked = Me.chkbxFormLocked.Value
ctl.Locked = Me.chkbxFormLocked.Value
private sub chkbxFormLocked_afterupdat e()
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.chk bxFormLock ed.value
end if
end if
next
end sub
dim ctl as control
for each ctl in me.controls
if ctl.controltype<>aclabel then
if ctl.name<>"chkbxFormLocked
me(ctl.name).locked=me.chk
end if
end if
next
end sub
ASKER
Same error using:
Me(ctl.Name).Locked = Me.chkbxFormLocked.Value
Me(ctl.Name).Locked = Me.chkbxFormLocked.Value
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.
correct any errors raised
if that doesn't fix it, your form could be corrupted.
create a new form and try the codes again.
ASKER
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
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....
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....
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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