Hello,
I'm trying to create a query that includes a count of records related to it from a child table. I did try to find answers on this, but something is eluding me. I'm pretty much a novice with Access, so hoping someone can help.
I have a parent table and a related child table (one-to-many). The child table has a text field used (with a lookup) to categorize reach child record by one of three categories (let's say CatA, CabB, and CatC for this). Let's say I have 100 records in the parent table, and I want the query to produce one row for each of the parent records, each with three separate columns corresponding to the three categories. These columns would display the count of the related records in that category.
What I did in query design view:
- Added the two tables
- Changed the join type to display all records from parent table
- Added the fields I needed from the parent table
- Added the category field from the child table
- Clicked on the Totals button
- In the grid, changed the Totals row to "Count" for the category field (and left the other fields as "Group By")
- Changed the criteria to be ="CatA"
Then I ran the query before adding columns for the two other categories. I got this error message:
"Datatype mismatch in criteria expression"
Clearly, Count doesn't work like I think it should (i.e. adding criteria to filter what each column actually counts). Am I on the wrong track here? Is there another way to go about this and get the same resulting file?
Thanks for any advice!