开发者

Using DCount for more than one domain in Access 2007

开发者 https://www.devze.com 2023-03-13 08:12 出处:网络
I am basically trying to count the number of occurences of Item A IF the value of Item B 开发者_C百科is =\'string\'.

I am basically trying to count the number of occurences of Item A IF the value of Item B 开发者_C百科is ='string'.

I have been doing it like this- which turns up an error:

DCount("[Item A]", "[Table]", "[Item A] > 1 and [Item B] = 'apples'")

Unfortunaltey, B is in a different table, so MS Access doesn't recognize it when I run the query. What else can I do?

Please help.


You need to join the two tables. DCount is "Domain" Count. Domain is basically the values that fall under a single field/column in a single table/query, hence the restriction to a single table. The simplest way to resolve this I think would be to make a new query that joins both tables, making both item a and item b accessible from the same place:

SELECT [item a], [item b]
FROM [Table] AS t
INNER JOIN [Other Table] AS ot
    ON t.itemID = ot.itemID

Obviously I don't know the name of your other table, or the names of the fields you would need to do the join on (specified by ON in that query), so replace field and table names where appropriate. So, say I named that query "productA-B", your DCount usage would look like:

DCount("[item a]", "productA-B", "[item a] > 1 AND [item b] = 'apples'")


It is a long time since i used acceess, but can you not prefix [Item B] with the table name? i.e. [other_table].[Item B]

0

精彩评论

暂无评论...
验证码 换一张
取 消