How to lock record in subform

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

Guest

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
 
R

Ron2006

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

Ron2006

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
 

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

Top