title: Moving Through a Recordset evaluating current month plus two previous months
body: <p>I am writing a VBA macro to manage a database for cell phones.  What I am testing for is that if any of the previous months (current month plus previous two months) have activity. If all three months show "no usage" then we will check a Boolean box true to then deactivate the line.</p>
  
  <p>I have the logic written partially.  </p>
  
  <p>I started with a crosstab query that has calculated fields.  This way my query always maintains structure.  I am evaluated the fields for the value.  If the field value is great than zero, move on.  If it is equal to zero, then set a counter to 1.  Once the counter reaches three, mark the line's Boolean box as true for non-usage.</p>
  
  <p>The code is listed below.  I have two columns before the columns of months on my table, therefore my rsIndexes start at 2 and go through 12 and the entire table has 14 columns.  With the For Next loop that I created I can manage the situation that occurs very naturally such as 7,6,5 (Jul, Jun, May).</p>
  
  <p>Here's my issue: How do you use this structure and move through the recordset when you have to evaluate data with recordset indexes of 1, 12, 11 (Jan, Dec, Nov).  Is the movement from 1 back to 12 then to 11 that is my issue.</p>
  
  <pre><code>Sub detectNonUsage2()
  
  Dim rsNonUsageList As New ADODB.Recordset
  
  lastMonthIndex = [Forms]![frmNonUsageLogic]![cboCurMonth].ListIndex
  
  lastMonthIndex = (lastMonthIndex + 2)
  
  MsgBox lastMonthIndex
  
  rsSQL = "Select * from qryDeviceIDbyMonth"
  
  rsNonUsageList.Open rsSQL, CurrentProject.Connection, adOpenKeyset, adLockReadOnly
  
  Do Until rsNonUsageList.EOF
  
      curVal = rsNonUsageList(lastMonthIndex)
  
      curMonth = rsNonUsageList(lastMonthIndex).Name
      curCount = 0
  
      For curField = lastMonthIndex To lastMonthIndex - 2 Step -1
  
             If rsNonUsageList(lastMonthIndex) = 0 Then
                  curCount = curCount + 1
              Else
  
              End If
  
          curMonth = rsNonUsageList(curField).Name
          Debug.Print curMonth
  
      Next curField
  
          If curCount &gt;= 3 Then
          'set flag for nonUsage
          Else
  
          End If
  
          rsNonUsageList.MoveNext
  
      Loop
  
      rsNonUsageList.Close
  
  End Sub
  </code></pre>