Hi again. Ok, that's a very different proposition than I had read from your first question.
There's a couple of different approaches to solve this.
One would be to write a vba function to step through the recordset and determine whether the conditions you've outlined are met or not. You could use the function to return a true or false in a field in a query, and then select your records according to that result.
However, you can also use SQL to do this although it's tricky.
The first issue is that the order of the records inyour source table is critically important in this situation. Therefore, I recommend creating a query called 'Observations' which explictly sorts the data in your source table into three columns:
[River] Order Ascending
[ObservationTime] Order Ascending
[WaterTemperature_C] Not sorted.
If there is any possibility of null values in the data set, ensure that there are no null water temps in this query by using the Is Not Null criteria in all three fields.
Then create another query and use the following SQL for this new query
Code:
SELECT Observations.River, Observations.ObservationTime, Observations.WaterTemperature_C, IIf([WaterTemperature_C]>0,0,(Select Count (*) FROM [Observations] as Temp WHERE (([Temp].[River] = [Observations].[River]) AND ([Temp].[ObservationTime] < [Observations].[ObservationTime]) AND ([Temp].[ObservationTime] >DMax("ObservationTIme","Observations","[ObservationTime]<#" & [Observations].[ObservationTime] & "# AND [WaterTemperature_C]>0") )))+1) AS ConsecutiveNum
FROM Observations
ORDER BY Observations.River, Observations.ObservationTime;
This should create a calculated column that counts the number of consecutive subzero temperature readings since the last zero/positive reading for that river.
Then you can use a criteria of >=6 in that column to select the rows you wish to delete.
Essentially this does use a conditional if statement to return a value of 0 when the water temp is positive, and if the temp is negative, then it uses a subquery to count the number of negative temperature records that have a time greater than the time of the last positive reading, but less than the current reading for the same river.
Hopefully that helps you out.