SubProf 0 Light Poster

Hello Everyone,

I have a large database where I'm using Dlookup to find the next record in the database. I need to find the next record providing it meets a specific criteria. If it doesn't meet the criteria then I need to look at the next record to see if it meets the criteria. I tried using a subquery where the new table contained all the records that met the criteria but when I used Dlookup it didn't find the next record since the numbers on the records were no longer sequential (i.e. 251, 252, 253 etc). Here is my code.

SELECT TOP 1 UserName, Max(time) AS MaxOftime, RecNumber, DLookUp('[UserName]','table1','[RecNumber] = ' & [RecNumber]+1) AS Expr1, DLookUp('[time]','table1','[RecNumber] = ' & [RecNumber]+1) AS Expr2 
FROM table1
WHERE (((time)<(Now()-1)))
GROUP BY UserName, RecNumber, DLookUp('[UserName]','table1','[RecNumber] = ' & [RecNumber]+1),  DLookUp('[time]','table1','[RecNumber] = ' & [RecNumber]+1)
HAVING ((UserName)="Bob")) ORDER BY Max(time) DESC;

If anyone has any suggestions as to how to rectify this it would be much appreciated.

Thanks in advance,

SubProf