Referencing controls on a subform

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

Guest

I cannot successfully reference controls on a subform. I am following an
example in an Access manual by placing the following statement in the main
form:

Forms!Mainform!Subform.Form!SubformControl.Enabled = True

The error message I get at runtime says that it can't find the "field"
called Subform. What am I doing wrong?
 
Is your statement here the actual statement you are using? What you have here is
a generic statement and you are to use your actual forms, field and control
names.
Definitions:
Mainform - use the actual name of your mainform, ex. FrmCustomer
Subform - open your main form in design view. Select the subform control. Open
properties, go to the Other tab and see the value for the Name property. Use
that value here.
Form - Refers to the form in the subform control. Leave the word "form".
Subform Control - Open your subform in design view. Select the control you want
to enable. Open properties, go to the Other tab and see the value for the Name
property. Use that value here.
Everything else stays the same.
 
Try
Forms!Mainform.SubForm![SubformControl].Enabled = True
or
me.SubForm![SubformControl].Enabled = True

HTH
Damon
 
Thanks for posting. Yes, of course I'm using real form names. I used
generic form names to better show what I was doing without having to explain
which names are what, like many do on this forum.

Knowing this, if you can see any reason why it won't work please post again.

By the way, I was puzzled by one thing you described here. As far as I can
see, controls have a Name property but forms (subforms) don't.

ctdak
 
Thanks for trying, but your suggestion doesn't work either.

The first one gives a runtime error "Application-defined or object-defined
error" and the second a compile error related to "Me".

Any other ideas?

ctdak


Damon Heron said:
Try
Forms!Mainform.SubForm![SubformControl].Enabled = True
or
me.SubForm![SubformControl].Enabled = True

HTH
Damon

ctdak said:
I cannot successfully reference controls on a subform. I am following an
example in an Access manual by placing the following statement in the main
form:

Forms!Mainform!Subform.Form!SubformControl.Enabled = True

The error message I get at runtime says that it can't find the "field"
called Subform. What am I doing wrong?
 
You would be better served if you posted the *actual* code that you
are using. Otherwise it isn't always evident what you are doing. There
is nothing wrong structurally with what you posted - hence the
question.

Generally, the best way to refer to the form is with the keyword Me
(look it up in help). Therefore, if you use something like ...

Me.SubformName.Form!SubformControl.Enabled = True

It should work just fine - or something else is wrong.

Note that a subform is a *control*. Therefore you need to use the
subform controls name - which isn't always the name of the *form* that
it holds.

BTW, all user defined objects have a name property.

- Jim
 
Your last sentence perhaps is the missing clue to the problem. Note in my
definition of subform I tell you to get the name of the subform control not the
subform. You are correct that a form (subform) does not have a Name property but
the subform control does! If you are using the name of the subform rather than
the name of the subform control, that is the problem!
 
The note in Jim's response hits the nail on the head!

The statement would be more clear like this:

Me.SubformControlName.Form!NameOfControlOnSubform.Enabled = True
 
They work on mine. ?? where are u putting the code? I put it in the main
form load event.
A number of questions.... what version of Access? Reference problems?
Look at Tools, References, for missing references. Also do u have the
latest service packs?
ctdak said:
Thanks for trying, but your suggestion doesn't work either.

The first one gives a runtime error "Application-defined or object-defined
error" and the second a compile error related to "Me".

Any other ideas?

ctdak


Damon Heron said:
Try
Forms!Mainform.SubForm![SubformControl].Enabled = True
or
me.SubForm![SubformControl].Enabled = True

HTH
Damon

ctdak said:
I cannot successfully reference controls on a subform. I am following an
example in an Access manual by placing the following statement in the main
form:

Forms!Mainform!Subform.Form!SubformControl.Enabled = True

The error message I get at runtime says that it can't find the "field"
called Subform. What am I doing wrong?
 
Yes, this was indeed my problem. Before I just double-clicked on the top
left corner of the subform control and always got a property sheet for
"Form". I've discovered that if you right click and select properties
instead at the same place, then you get the Subform property sheet. (Why the
difference I have no idea.) Once I got that I could see the subform name and
see that it was different than the form name. So, my problem is now solved
using the subform control name. The construct I had before works with this
name.

ctdak
 
Jim,

I got it working. You were correct - I was not using the subform control
name in my statement. That was the only problem. The manual I was referring
to makes no mention of the distinction between the subform name and the
subform control name. In fact it makes no mention of the latter at all. The
examples it gives refer only to the subform name. Thanks for your input. My
problem is solved.

It appears, by the way that either a "." or a "!" after "Me" works equally
as well here. I tried them both once I knew what my problem was.

ctdak
 
My problem is solved. I was using the subform name and not the subform
control name in my statement. See the other posts. Thanks for replying.

ctdak


Damon Heron said:
They work on mine. ?? where are u putting the code? I put it in the main
form load event.
A number of questions.... what version of Access? Reference problems?
Look at Tools, References, for missing references. Also do u have the
latest service packs?
ctdak said:
Thanks for trying, but your suggestion doesn't work either.

The first one gives a runtime error "Application-defined or object-defined
error" and the second a compile error related to "Me".

Any other ideas?

ctdak


Damon Heron said:
Try
Forms!Mainform.SubForm![SubformControl].Enabled = True
or
me.SubForm![SubformControl].Enabled = True

HTH
Damon

I cannot successfully reference controls on a subform. I am following an
example in an Access manual by placing the following statement in the main
form:

Forms!Mainform!Subform.Form!SubformControl.Enabled = True

The error message I get at runtime says that it can't find the "field"
called Subform. What am I doing wrong?
 
Back
Top