Opening a Recordset Based on Criteria
Sub OpenRst_WithCriteria()
Dim conn As ADODB.Connection
Dim rst As ADODB.Recordset
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 Employees WHERE ReportsTo is Null", _
conn, adOpenForwardOnly, adLockReadOnly
Do While Not rst.EOF
Debug.Print rst.Fields(1).Value
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
conn.Close
Set conn = Nothing
End Sub
Related examples in the same category