title: how to loop through the records of a subform, VBA Access 2010
body: <p>Here's my question: i have a subform inside a main form. The main form contains the customer number, and the subform contains the order for that customer. So one customer may have multiple orders. I want to create a buttom which when clicked moves to the next order for that customer. I have no issue doing this with the code:</p>
  
  <pre><code> Private Sub next_comp_Click()
   [Forms]![Customer]![Order Subform].SetFocus
   DoCmd.GoToRecord , , acNext
    end sub
  </code></pre>
  
  <p>where I have issues is when I get to the last order for that customer. I will like it to loop back to the first order. To do this i used this code:</p>
  
  <pre><code>Private sub next_comp_click()
  [Forms]![Customer]![Compressor Subform].SetFocus
  Dim dbcustomer As Database
  Dim rstorder As Recordset
  
  Set dbcustomer = CurrentDb
  Set rstorder= dbcustomer.OpenRecordset("orders", dbOpenSnapshot)
    With rstEmployees
      If .AbsolutePosition = - 1 Then
      MsgBox (.RecordCount)
      'DoCmd.GoToRecord , , acFirst
      Else
      DoCmd.GoToRecord , , acNext
      End If
    End With
   end sub
  </code></pre>
  
  <p>I used the MsgBox function to kind of debug to figure what record I am on (ultimately I want it to loop back to the first record as shown in the commented out code), but for some reason, it tells me i am always on the first record, i.e. it tells me the RecordCount is 1. This is not supposed to be so because most of the records I am working with have multiple orders. If I change the condition to something like If .AbsolutePosition = 3, it moves the records to the next until i get to the last or empty record and if i click next from there, it gives me the run-time error '2105' you cannot go to the specified record.</p>
  
  <p>I think the issue is the .AbsolutePositon property is not looking at the right form or table, but any answers will be much appreciated.</p>
  
  <p>Thank you in advance.</p>