How to change ENABLE property of subform by button on Main form

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

Guest

I am trying to open a form and subform for read only, i.e. with main form
fields Locked = True and subform control Enable = False. On the main form I
have a button to allow edit of the data. I am able to change the main form
fields controls to Locked = False, but cannot find a method to change the
subform control Enable = True. Can anyone please help.
 
Hi Irv,

If I understand you correctly, you can use the following code in the button
event that you want to enable the controls in the subform.

Private Sub cmdEnableControls()
if Forms!frmMainForm!subEmbeddedForm!txtEmployeeName.enabled = false then
Forms!frmMainForm!subEmbeddedForm!txtEmployeeName.enabled = true
else
Forms!frmMainForm!subEmbeddedForm!txtEmployeeName.enabled = false
end if
End Sub

You can either list each control as I did here, or you can iterate through
the controls collection and after checking its type (i.e. textbox, combo box,
etc.), then enable or disable appropriately. I prefer this method since you
don't have to update this section of code if you make changes to the subform.

Hope that helps.

Lance
 
Thanks for your reply Lance.

I have tried your suggestion on one field in the sub form , without success!
The main form is named "frmEdInv",
the subform is "frmInvDet"
the field I tried to change is "Detno".
The code I entered in the Private Sub is
Rem Enable Detail no. field on subform

If Forms!frmEdInv!frmInvDet!Detno.Enable = False Then
Forms!frmEdInv!frmInvDet!Detno.Enable = True
Else: Forms!frmEdInv!frmInvDet!Detno.Enable = False
End If

I receive an error message
" Can't find the field frmInvDet referred in your expression "
Have I missed something? I am fairly new to Access.
Thanks
Irving
 
Hi Irv,

I tried the same code with no problem so I am wondering if we are not
looking for a spelling error. Check to make sure that the form name is
exactly the same as it is in code. I think we should start there. The name
of the subform as it is embedded on the main form is what you need to have in
the code.

Let me know if you are still having a problem.

Lance
 
Thanks Lance

Silly me! I had given the Control on the main form a slightly different name!
Now works fine. Thanks again.

Irv
 
Back
Top