Hi Angela,
I'm not sure how (or if, even) you could do that in a query.
Here is some (quickly tested) code that seems to give the results you want:
'********VBA code (somewhat tested)**********
Public Sub StartEnd()
Dim dbs As DAO.Database: Set dbs = DBEngine(0)(0)
Dim rstSource As DAO.Recordset
Dim rstTarget As DAO.Recordset
Dim lngCount As Long
Dim lngStart As Long
Dim lngEnd As Long
Dim lngPrev As Long
Dim strSQL As String
strSQL = "SELECT setField FROM tblStartEndTest ORDER BY setField"
Set rstSource = dbs.OpenRecordset(strSQL, dbOpenDynaset)
Set rstTarget = dbs.OpenRecordset("tblStartEndResults", dbOpenDynaset)
With rstSource
.MoveFirst
lngStart = !setField
lngPrev = lngStart
lngCount = 1
.MoveNext
Do
If !setField = lngPrev + 1 Then
lngPrev = !setField
lngCount = lngCount + 1
Else
lngEnd = lngPrev
With rstTarget
.AddNew
!serStart = lngStart
!serEnd = lngEnd
!serCount = lngCount
.Update
End With
lngStart = !setField
lngPrev = lngStart
lngCount = 1
End If
.MoveNext
Loop Until .EOF
lngEnd = lngPrev
With rstTarget
.AddNew
!serStart = lngStart
!serEnd = lngEnd
!serCount = lngCount
.Update
End With
End With
rstSource.Close
Set rstSource = Nothing
rstTarget.Close
Set rstTarget = Nothing
Set dbs = Nothing
End Sub
'********End VBA Code********************
Copy and paste this into a standard module.
If you need any help following what it does, or getting it to work, please
post back.
Cheers,
Alex.