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

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
 
K

Klatuu

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.
 
P

pietlinden

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...
 

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