Expand|Select|Wrap|Line Numbers
- Select field1, field2
- FROM table
- WHERE ....
- GROUP BY field1, field2
Expand|Select|Wrap|Line Numbers
- field1 field2
- aa 1
- aa 6
- aa 1000
- bb 10
- bb 25
I tried using count(field1) but the result returns the count of field1/field2 rows (ie 1 in each of the above cases).
I found a convoluted way by outputing the results into a result table using SELECT INTO and running a seperate query to determine the counts but then found this did not work when I tried to open a recordset in VBA on the SELECT INTO (I get error number 3219: Operation Invalid).
So I then tried to use OpenQuery to create the results table. However, I think I have learned from these pages that I can't run a stored action query from VBA using the OpenQuery method and pass parameters to it in the same way as I pass parameters to a stored "non action" query when opening a recordset, so I've ended up with something like:
Expand|Select|Wrap|Line Numbers
- Select field1, count(field1)
- From (Select field1, field2
- FROM table
- WHERE ....
- GROUP BY field1, field2)