Moving Around in a Recordset
Sub MoveAround()
Dim conn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim fld As ADODB.Field
Dim strConn As String
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & CurrentProject.Path & "\mydb.mdb"
Set conn = New ADODB.Connection
conn.Open strConn
Set rst = New ADODB.Recordset
rst.Open "Select * from Customers where ContactTitle = 'Owner'", _
conn, adOpenForwardOnly, adLockReadOnly
Do While Not rst.EOF
For Each fld In rst.Fields
Debug.Print fld.Name & " = " & fld.Value
Next
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
conn.Close
Set conn = Nothing
End Sub
Related examples in the same category