enable/unlock a subform control based on a mainform checkbox value

  • Thread starter Thread starter pietlinden
  • Start date Start date
P

pietlinden

I must be doing something stupid, and I can't figure out what it is.
I'm working with Keri Hardwick's article here:
http://www.mvps.org/access/forms/frm0031.htm

I have a checkbox on my main form, "chkHasSites", and a subform on a
tabbed control on my main form has a subform called "Metastatic
Disease Sites" (Yes, I know it shouldn't have spaces!) What I want to
do when the chkHasSites is false is disable entering new records into
the subform "Metastatic Disease Sites".

When I try this:

Private Sub ToggleSubform()
' If a patient has Metastatic Disease Sites, the checkbox should
be checked.
' in order to add MDSs, you need to CHECK the checkbox. If the box
is not checked, disable the subform
Forms![frmPatient]![Metastatic Disease Sites].Form![Metastatic
Disease Site].Enabled = Me.chkHasSites
Forms![frmPatient]![Metastatic Disease Sites].Form![Metastatic
Disease Site].Locked = Not Me.chkHasSites

End Sub

I get Error 2164, "You can't disable a control while it has focus".

If I do the obvious and do
me.Controls("SomeOtherControl").SetFocus

and then try it, it still fails. So what am I missing and how do i
fix it?

If you need more info - ask! (I think I got it all, but I've thought
that before...)
Thanks!
Pieter
 
Use the After Update event of the checkbox.

Me.SubFormControlName.Form.AllowAdditions Not Me.chkHasSites

Note - you do not use the name of the form that is being used as a subform.
You use the name of the subform control on the main form.

You also need to put the same line of code in the form current event so it
will handle existing and new records correctly.
 
Use the After Update event of the checkbox.

Me.SubFormControlName.Form.AllowAdditions Not Me.chkHasSites

Note - you do not use the name of the form that is being used as a subform.
You use the name of the subform control on the main form.

You also need to put the same line of code in the form current event so it
will handle existing and new records correctly.
--
Dave Hargis, Microsoft Access MVP

I must be doing something stupid, and I can't figure out what it is.
I'm working with Keri Hardwick's article here:
http://www.mvps.org/access/forms/frm0031.htm
I have a checkbox on my main form, "chkHasSites", and a subform on a
tabbed control on my main form has a subform called "Metastatic
Disease Sites" (Yes, I know it shouldn't have spaces!) What I want to
do when the chkHasSites is false is disable entering new records into
the subform "Metastatic Disease Sites".
When I try this:
Private Sub ToggleSubform()
' If a patient has Metastatic Disease Sites, the checkbox should
be checked.
' in order to add MDSs, you need to CHECK the checkbox. If the box
is not checked, disable the subform
Forms![frmPatient]![Metastatic Disease Sites].Form![Metastatic
Disease Site].Enabled = Me.chkHasSites
Forms![frmPatient]![Metastatic Disease Sites].Form![Metastatic
Disease Site].Locked = Not Me.chkHasSites
I get Error 2164, "You can't disable a control while it has focus".
If I do the obvious and do
me.Controls("SomeOtherControl").SetFocus
and then try it, it still fails. So what am I missing and how do i
fix it?
If you need more info - ask! (I think I got it all, but I've thought
that before...)
Thanks!
Pieter

Thanks! I think I figured it out, but I'll check Monday...
 
Back
Top