Query Problem

D

Dudy

I have a subform that brings up recipe ingredients.
The subform record source is Recipe Ingredients table.
I place a textbox on the subform that pull a calculation from the query.
The control source for the textbox is set to
=[UnitExt Query]![UnitCost]
but when i run the subform it comes up #NAME?
If I run the query the calculation is correct.
What am I doing wrong?
 
J

John W. Vinson

I have a subform that brings up recipe ingredients.
The subform record source is Recipe Ingredients table.
I place a textbox on the subform that pull a calculation from the query.
The control source for the textbox is set to
=[UnitExt Query]![UnitCost]
but when i run the subform it comes up #NAME?
If I run the query the calculation is correct.
What am I doing wrong?

Just the syntax. You can't refer to a query unrelated to the Form, or by query
name.

If the UnitExt Query is (or can be made) part of the Form's Recordsource, just
use the fieldname. If not, use the DLookUp function:

=DLookUp("[UnitCost]", "[UnitExt Query]", <some optional criteria>)

where the criteria string is a String consisting of a valid SQL WHERE clause
(without the word WHERE) which returns the unit cost that you want - perhaps

"[IngredientID] = " & [txtIngredientID]

if there's a control on the form with that name.

John W. Vinson [MVP]
 
G

Guest

Thanks for the info, suggestion, and example John. I encountered the same
problem today & your code worked perfectly.

-=Brian
John W. Vinson said:
I have a subform that brings up recipe ingredients.
The subform record source is Recipe Ingredients table.
I place a textbox on the subform that pull a calculation from the query.
The control source for the textbox is set to
=[UnitExt Query]![UnitCost]
but when i run the subform it comes up #NAME?
If I run the query the calculation is correct.
What am I doing wrong?

Just the syntax. You can't refer to a query unrelated to the Form, or by query
name.

If the UnitExt Query is (or can be made) part of the Form's Recordsource, just
use the fieldname. If not, use the DLookUp function:

=DLookUp("[UnitCost]", "[UnitExt Query]", <some optional criteria>)

where the criteria string is a String consisting of a valid SQL WHERE clause
(without the word WHERE) which returns the unit cost that you want - perhaps

"[IngredientID] = " & [txtIngredientID]

if there's a control on the form with that name.

John W. Vinson [MVP]
 

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