Get result set by column name : Recordset Filter « Access « VBA / Excel / Access / Word






Get result set by column name

 
Sub MyFirstConnection()
    Dim myConnection As ADODB.Connection
    Dim myRecordset As ADODB.Recordset
    Dim strSQL As String
    
    strSQL = "SELECT * FROM Employees ORDER BY LastName"
    
    Set myConnection = CurrentProject.Connection
    
    Set myRecordset = New ADODB.Recordset
    myRecordset.Open strSQL, myConnection
    
    Do Until myRecordset.EOF
       Debug.Print myRecordset.Fields("FirstName"), _
                   myRecordset.Fields("LastName")
       myRecordset.MoveNext
    Loop
    myRecordset.Close
    myConnection.Close
    Set myConnection = Nothing
    Set myRecordset = Nothing
End Sub

 








Related examples in the same category

1.Use Recordset filter
2.Filtering Records Using the Filter Property
3.Filtering Records with an SQL Clause
4.Get the number of recorders which meet the criteria
5.Filtering a Recordset
6.Filtering a Recordset by using the Date type field