It's also easy when looping through a recordset from VB. In a query, it's more complex because Access has no built-in method to refer to the previous record.
However, you can find the previous record with the highest ID and a different Value. This creates a possible grouping expression:
SELECT First(Value) As Val, Count(*) As N
FROM
(SELECT
A.ID,
A.Value,
(Select Top 1 ID From YourSample B
Where A.Value<>A.Value And A.ID<B.ID
Order by ID Desc
) AS grp
FROM YourSample A
) As C
GROUP BY grp
I hope this helps
(°v°)
Main Topics
Browse All Topics





by: peter57rPosted on 2009-11-05 at 08:17:19ID: 25751008
You will need to add a 'groupno' field to the table.
Then read the records using a recordset .Aallocate groupno 1 to the first record, and keep allocating number 1 until you get a change in 'value', then increment the group number and repeat until the end oof file.
The recordset MUST specify the ID field as the sort order otherwise you cannot guarantee the sequence will be what you want.
Once you have allocated the group numbers you can then run a straightforward Group by query to count the records in each group.