View Single Post
  #24  
Old June 4th, 2009, 03:50 PM posted to microsoft.public.access.forms,microsoft.public.access.gettingstarted
Dirk Goldgar
external usenet poster
 
Posts: 2,529
Default Can’t Display Number of SUBFORM Items on MAIN Form... trying to use [RecordCount]

wrote in message
...
Did I get the field and table names correct?


I have posted a picture of my database relationships for your reference
because I am not sure which fields your SQL query needs since it
references BOTH tblRecipes and tblRecipeIngredients, and both tables
contain a recipe ID field.


Thank you, that's very helpful.

It is called "fldRI_RecipeID" in tblRecipeIngredients and the one in
tblRecipes is called "fldRecipeID."


And that is the source of the problem; or at least, *a* problem. The SQL
of the query should be amended to:

SELECT
DCount("*","tblRecipeIngredients",
"fldRI_RecipeID=" & Nz(fldRecipeID,0))
AS IngredientCount,
*
FROM tblRecipes;

That is to say, return all fields of all records in tblRecipes, plus a
calculated field for each record which is a count of all records in
tblRecipeIngredients where fldRI_RecipeID in that table equals fldRecipeID
in tblRecipes.

What happens when you open the recordsource query directly as a
datasheet? Does that give an error?


I did this, and the field in datasheet view contained all 0s. **BUT**....
then I closed and re-opened the database. This time, when I opened the
form the "Number of Ingredients" textbox results in #Error, and a separate
message box persists that says: "The expression you entered as a query
parameter produced this error: 'Object or class does not support the set
of events'"


That's kind of an odd error message for you to get, but Access 2007 seems to
have changed some of the standard error messages generated by particular
sorts of errors. The referemce to a "query parameter" is a clue that Access
doesn't recognize one of the names in the DCount() expression, since any
unrecognized name in a query is assumed to be a parameter.

I am not sure why it didn't give the error message at first. Maybe it is
because I had not yet closed and reopened the database????


I don't know, either, but try the revised query above, first checking to
see if it works when opened directly as a datasheet.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)