How to lock record in subform

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How can I write code to lock record in subform (continous form) by checking
one field in subform.
My mainform has 2 combo box (unbound)
My subform will show all records are linked with 2 combo box in main form
(Set linkmasterfield & childfields property on design form).
In generally, all user can edit records in subform but
in some case, I want to lock all records if field [proved] in subform is -1
(yes/no)
 
One way is to conditionally lock and disable all controls with code in the
subform's Current event procedure:

Dim ctrl As Control

On Error Resume Next
For Each ctrl In Me.Controls
ctrl.Locked = Proved
ctrl.Enabled = Not Proved
Next ctrl

If you want to lock only some controls, leaving others such as command
buttons etc available to the user then set the Tag property of those controls
you want to lock/disable to something such as 'LockMe'. You can then just
lock/disable those controls:

Dim ctrl As Control

For Each ctrl In Me.Controls
If ctrl.Tag = "LockMe" Then
ctrl.Locked = Proved
ctrl.Enabled = Not Proved
End If
Next ctrl

In the second example you don't need the error handling as you'd only tag
controls which can be locked/disabled, whereas the first tries to
lock/disable all controls and raises an error if the control type doesn't
allow this, e.g. labels.

Ken Sheridan
Stafford, England
 
Or you can do the following in the oncurrent event of the subform

if me.proved = true then
me.allowedits = false
else
me.allowedits = true
endif

or another way

me.allowedits = not me.proved



Ron

How can I write code to lock record in subform (continous form) by checking
one field in subform.
My mainform has 2 combo box (unbound)
My subform will show all records are linked with 2 combo box in main form
(Set linkmasterfield & childfields property on design form).
In generally, all user can edit records in subform but
in some case, I want to lock all records if field [proved] in subform is -1
(yes/no)
 
And also repeat that same code in the afterupdate event of the [proved]
field.

In both cases this is saying that once [proved] is set, no fields in
the record can be changed from this form.

Ron
 
Back
Top