I am trying to loop through my table but when I run the program it starts on ID_fk 171 instead of 1 and I do not know why. Hope you can help!
It starts on 171 and goes thru 361 which is the end.
'--------------------------------
Private Sub cmdADOlooping_Click()
On Error GoTo ErrorHandler
Dim strSQL As String
Dim rs As New ADODB.Recordset
'we will be opening our table
strSQL = "SELECT UniqueCustomersWithPickups.ID_fk, UniqueCustomersWithPickups.PC, UniqueCustomersWithPickups.FirstVisit, UniqueCustomersWithPickups.ClientType FROM UniqueCustomersWithPickups ORDER BY UniqueCustomersWithPickups.ID_fk, UniqueCustomersWithPickups.PC;" 'define the SQL result that you want to loop
rs.Open strSQL, CurrentProject.Connection, adOpenDynamic, adLockOptimistic
With rs
'Ensure recordset is populated
If Not .BOF And Not .EOF Then
'not necessary but good practice
.MoveLast
.MoveFirst
Debug.Print rs.Fields("ID_fk") & " " & rs.Fields("PC") ' placed here to see if I am on first record in my table I Am!
While (Not .EOF)
'print info from fields to the immediate window
Debug.Print rs.Fields("ID_fk") & " " & rs.Fields("PC")
.MoveNext
Wend
End If
.Close
End With
ExitSub:
Set rs = Nothing
Exit Sub
ErrorHandler:
Resume ExitSub
End Sub