This is AIRCODE and untested but the procedure will look something like:
Code:
Private Sub TagRecord()
On Error GoTo Err_TagRecord
'-- This procedure expects the records to be ordered by [CustID], [PurchNo], [ProdRef] in the query
'-- It further expect there will *always* be a record that satisfies the selection
'-- This uses DAO and requires a reference to that Object Library
Dim MyRs As DAO.Recordset
Dim MyDb As DAO.Database
Dim CurID As String
Dim Skipping As Boolean '-- True if moving down the recordset to the next CustID
Skipping = False '-- Initial value
Set MyDb = CurrentDb()
Set MyRs = MyDb.OpenRecordset("YourQueryName", dbOpenDynaset)
With MyRs
CurID = !CustID '-- Initial CustID
Do While Not .EOF
If Not Skipping Then
If Not SubGroup(!ProdRef) Then
.Edit
!Flag = True
.Update
Skipping = True
.MoveNext
Else
If !CustID <> CurID Then
CurID = !CustID
Skipping = False
Else
.MoveNext
End If
End If
Else
If !CustID <> CurID Then
CurID = !CustID
Skipping = False
Else
.MoveNext
End If
End If
Loop
End With
Exit_TagRecord:
On Error GoTo 0
MyRs.Close
Set MyRs = Nothing
Set MyDb = Nothing
Exit Sub
Err_TagRecord:
MsgBox "Error No: " & Err.Number & vbCr & _
"Description: " & Err.Description
Resume Exit_TagRecord
End Sub
Function SubGroup(InValue As String) As Boolean
'-- Do whatever you need to do to determine if the [ProdRef]
'-- being passes is a Sub or not and return SubGroup = True
'-- if this record is a SubGroup
If Left(InValue, 1) = "R" Then
SubGroup = True
Else
SubGroup = False
End If
End Function