Full Version: Locking/unlocking A Control In Datasheet View
UtterAccess Forums > Microsoft® Access > Access Forms
blobbles78
Hi all,
I have a 3 controls in a subform, a combo box, a text box and a tick box. The user needs to be able to use the tick box in the subform - ticking or unticking at any time. However the user is not able to edit the combo box or description box in the sub form, when the main form is opened normally. All this is fine, I have set the 2 controls I want locked in the sub form to Locked = True in design view and all works as described.
However, when the main form is opened for adding a new record, the user needs to be able to select items in the sub form combo and enter data in the text box as well as using the tick box. I thought this would be easy - I detect when the main form is opened for adding a record and set the combo and text box Locked values = False. But this doesn't seem to be possible for controls in datasheet view - I get a "Object doesn't support this property or method" error when I try and set them.
Am I missing something?
This code is in the main form load event - I use the OpenArgs to check if the forms being opened for adding a record:
CODE
    If Me.OpenArgs = "Adding record" Then
        'Enable editing on sub form
        Me.frmItemSub.Form.BusinessImpactTypeID.Locked = False
        Me.frmItemSub.Form.ImpactDescription.Locked = False
    Else
        'Lock down form
        Me.frmItemSub.Form.BusinessImpactTypeID.Locked = True
        Me.frmItemSub.Form.ImpactDescription.Locked = True
    End If

Thanks!
blobbles78
Actually, sorry, I get the "Application-defined or object-defined error" error, I got my errors confused!
missinglinq
Me.frmItemSub.Form.BusinessImpactTypeID.Locked = False
Is frmItemSub the name of the Subform Control or the name of the Form the Subform is based on? They are not always the same, and for the reference to work it has to be the name of the Subform Control.
Also, if I were doing this, instead of using the OpenArgs and passing "Adding record" to decide when to lock/unlock the controls I'd use the OnCurrent event of the main form.
CODE
Private Sub Form_Current()
If Me.NewRecord Then
  'Set the controls as you want when adding new record
Else
  'Set the controls as you want when not adding new record
End If
End Sub

Linq ;0)>
blobbles78
Yep, the name is correct (can see it through the intellisense using the me. notation)
I have other reasons for using the OpenArgs event, it shouldn't have any effect anyhow...
Could it be that the sub form isn't loaded at this stage and therefore I can't access the controls? Are subforms loaded before or after the main forms load event?
blobbles78
OK, think I solved it.
moved the locking/unlocking to the open event of the subform, checking the main forms OpenArgs using the Forms!frmMainForm.Form.OpenArgs = "Adding Record" code.
HAs far as I can tell, the sub form isn't loaded at the time the other code runs, so I can't set the controls locked value.
Thanks!
missinglinq
Actually what I consider to be one of the biggest quirks of Access is that the Subforms load before the Main form does.
But I always go with whatever works!
Linq ;0)>
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.