title: Cycling through an Access recordset provides an incorrect count
body: <p>I've added VBA code (below) to cycle through the results of an Access query.  The intent of this code is to count the number of times 500 appears in a specific column.  Once it hits 500, it grabs the time and adds 30 minutes.  The client doesn't want any 500 counted again in they appear in a 30 minute window.</p>
  <p>This works well until the last time is after 11:30 PM.  After 11:30 PM, the &quot;MyEnd&quot; variable gets set to an AM time on the next day.  It exits the loop and then counts the next 500; which throws my actual count off my 1.</p>
  <p>I could subtract 1 from the count but I don't know if this will always be true.  Their could be multiple 500s and the count would be off as well.</p>
  <p>I trying to determine how to handle the last 2 times the code finds 500 after 11:30 PM.</p>
  <p>Any suggestions would be greatly appreciated.  Thanks for your help.....</p>
  <pre><code>Dim strSQL As String
  Dim rs As DAO.Recordset
  Dim MyStart As Date
  Dim MyEnd As Date
  Dim CntA As Integer
      
  CntA = 0
  MyStart = 0
      
  strSQL = &quot;SELECT * FROM FurDet ORDER BY FurDet.Time&quot;
          
  Set rs = CurrentDb.OpenRecordset(strSQL)
      
  If Not rs.BOF And Not rs.EOF Then
          
       rs.MoveFirst
              
       While (Not rs.EOF)
          
            DoEvents
                      
            If rs.Fields(&quot;503D&quot;) = 500 Then
                  
                 MyStart = TimeValue(rs.Fields(&quot;Time&quot;))
                 MyEnd = TimeValue(MyStart + &quot;0:30&quot;)
                  
                 CntA = CntA + 1
                  
                 Do Until TimeValue(rs.Fields(&quot;Time&quot;)) &gt; TimeValue(MyEnd) Or rs.EOF = True                        
                      DoEvents                        
                      rs.MoveNext                        
                      If rs.EOF = True Then Exit Do                        
                 Loop
                  
            End If
              
            If rs.EOF = True Then
  '               do nothing
            Else
                rs.MoveNext
            End If
                      
       Wend
          
  End If
     
  Debug.Print CntA
  </code></pre>