Referencing a subform control on a tab control

D

Dennis

In Access 2003, I have a linked bound subform on a Tab. I want to set some
control properties in that subform if the user clicks the tab for that form.
So far, every bit of attempted syntax hasn't worked. Can someone PLEASE tell
me how to do that? (Specifically, I want to set the Enabled property of
certain controls on the subform.)

Thanks!
 
D

Douglas J. Steele

The fact that the subform is on a tab is irrelevant.

The syntax from the parent form is

Me!NameOfSubformControl.Form!NameOfControlOnSubform.Enabled = False

or from somewhere else

Forms!NameOfParentForm!NameOfSubformControl.Form!NameOfControlOnSubform.Enabled
= False

Note that the name of the subform control on the parent form may be
different than the name of the form being used as a subform.
 
D

Dennis

I'd love to say that worked, but it didn't. Below is the syntax I attempted:

Me!subApplicantStatus.Form!ApplicationStatus.Enabled = False

where "subApplicantStatus" is the name of the subform control on the parent,
and "ApplicationStatus" is the name of the control on the subform that I want
to disable. I get this error:

"Runtime error 2164 - You can't disable a control while it has the focus"

But it doesn't have the focus; I've not executed any SetFocus commands.

Any thoughts?

Thanks

Dennis
 
R

Rick Brandt

Dennis said:
I'd love to say that worked, but it didn't. Below is the syntax I
attempted:

Me!subApplicantStatus.Form!ApplicationStatus.Enabled = False

where "subApplicantStatus" is the name of the subform control on the
parent, and "ApplicationStatus" is the name of the control on the
subform that I want to disable. I get this error:

"Runtime error 2164 - You can't disable a control while it has the
focus"

But it doesn't have the focus; I've not executed any SetFocus
commands.

Any thoughts?

It is not required that YOU do something to set focus. On a form with at
least one control capable of receiving focus there is always a control that
DOES have focus. Even if the form itself does not have focus.

In the case of a form/subform the main form as well as every subform will
have a control that has current focus regardless of which form your cursor
is in. You just need to add some code to move focus of the subform to some
other control before you try to disable the desired one.
 
D

Dennis

That was it! I explicity SetFocus to "some control" on the subform, and then
was able to disable the control in question. My thanks to you and Doug!

Dennis
 
G

Graham Mandeno

Hi Dennis

A control on a form (or subform) can have the focus in the context of that
form, even though the form does not currently have the focus.

You might need to do something like this:

With Me!subApplicantStatus.Form
If .ActiveControl Is !ApplicationStatus Then
![some other control].SetFocus
End If
!ApplicationStatus.Enabled = False
End With
 
D

Dennis

I love these newsgroups.

Thanks!




Graham Mandeno said:
Hi Dennis

A control on a form (or subform) can have the focus in the context of that
form, even though the form does not currently have the focus.

You might need to do something like this:

With Me!subApplicantStatus.Form
If .ActiveControl Is !ApplicationStatus Then
![some other control].SetFocus
End If
!ApplicationStatus.Enabled = False
End With
--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand

Dennis said:
I'd love to say that worked, but it didn't. Below is the syntax I
attempted:

Me!subApplicantStatus.Form!ApplicationStatus.Enabled = False

where "subApplicantStatus" is the name of the subform control on the
parent,
and "ApplicationStatus" is the name of the control on the subform that I
want
to disable. I get this error:

"Runtime error 2164 - You can't disable a control while it has the focus"

But it doesn't have the focus; I've not executed any SetFocus commands.

Any thoughts?

Thanks

Dennis
 

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