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
"Nova" wrote:
[Quoted Text] > 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)
|