Private Sub Command486_Click()
Dim rs As DAO.Recordset
Dim lngCounter As Long
Dim strCurrentShowTitle As String
Dim strSQL As String
DAO.DBEngine.SetOption dbMaxLocksPerFile, 100000
strSQL = "Select ShowTitle, Season, Episode, EpisodeNumberTotal " & _
"FROM TV " & _
"ORDER BY ShowTitle, Season, Episode;"
Set rs = CurrentDb.OpenRecordset(strSQL, dbOpenDynaset)
lngCounter = 0
If rs.RecordCount > 0 Then
strCurrentShowTitle = rs!ShowTitle
Else
GoTo EmptyRecordset
End If
Do Until rs.EOF
If rs!ShowTitle = strCurrentShowTitle Then
lngCounter = lngCounter + 1
Else
lngCounter = 1
strCurrentShowTitle = rs!ShowTitle
End If
rs.Edit
rs!EpisodeNumberTotal = lngCounter
rs.Update
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
Exit Sub
EmptyRecordset:
MsgBox "Empty Recordset"
End Sub