subform not working properly

J

Jerry Crosby

Let me see if I can sufficiently describe this problem...

I have a form with a command button which runs a query that uses the data
from two fields on the subform. The query references the data with
"Forms!SubFormName!FieldName" The form record source is a table.

When opened on its own, the command button works properly.

Now, I use that form as a subform on a main form, which has as its record
source a table also. The main form record source table has a one-to-many
relationship to the subform record source table.

However, when I activate the command button when the form is used as a
subform, I am prompted for the data fields in the subform. It's not picking
up the data from those fields (even though I've entered it into the subform)
when it runs the query.

I fear I've murdered the explanation of this problem. I apologize. Feel
free to ask for clarification.

Jerry
 
R

RuralGuy

When a form is used as a SubForm, the form is no longer reachable on its own.
You must go through the Main Form to reference the SubForm.

Refer to Form and Subform properties and controls
http://www.mvps.org/access/forms/frm0031.htm

Let me see if I can sufficiently describe this problem...

I have a form with a command button which runs a query that uses the data
from two fields on the subform. The query references the data with
"Forms!SubFormName!FieldName" The form record source is a table.

When opened on its own, the command button works properly.

Now, I use that form as a subform on a main form, which has as its record
source a table also. The main form record source table has a one-to-many
relationship to the subform record source table.

However, when I activate the command button when the form is used as a
subform, I am prompted for the data fields in the subform. It's not picking
up the data from those fields (even though I've entered it into the subform)
when it runs the query.

I fear I've murdered the explanation of this problem. I apologize. Feel
free to ask for clarification.

Jerry

_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.
 
J

Jerry Crosby

RG,

Thanks for pointing me to that chart, but it hasn't seemed to help. If I'm
reading that chart correctly...

If I'm on the subform, and I want to refer to a control on the subform, I
simply use "Me!ControlName"

But the query still prompts me for "Me!ControlName" (And yes, I've
substituted the actual control name in my code.)

That format doesn't appear to follow your comment that you must go through
the main form to reference the subform.

Am I missing something?

Jerry
 
J

Jerry Crosby

RG,

I got it to work. I looked elsewhere on that chart and tried something that
seemed to refer back to the main form. I used
Forms!Mainform!Subform.Form!ControlName and it worked.

Thanks.

Jerry
 
R

RuralGuy

Thanks for posting back Jerry. Glad you got it working.

RG,

I got it to work. I looked elsewhere on that chart and tried something that
seemed to refer back to the main form. I used
Forms!Mainform!Subform.Form!ControlName and it worked.

Thanks.

Jerry

_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.
 
J

John Vinson

I have a form with a command button which runs a query that uses the data
from two fields on the subform. The query references the data with
"Forms!SubFormName!FieldName" The form record source is a table.

When opened on its own, the command button works properly.

Now, I use that form as a subform on a main form, which has as its record
source a table also. The main form record source table has a one-to-many
relationship to the subform record source table.

However, when I activate the command button when the form is used as a
subform, I am prompted for the data fields in the subform. It's not picking
up the data from those fields (even though I've entered it into the subform)
when it runs the query.

Correct: the Subform is not open in its own right and it is not part
of the Forms collection.

To reference a control on a Subform you must go through the mainform,
and through the name of the Subform control (which might or might not
be the same as the name of the form which it contains):

Forms!mainform!subformname.Form!controlname


John W. Vinson[MVP]
 
Top