Filtering Records with an SQL Clause : Recordset Filter « Access « VBA / Excel / Access / Word






Filtering Records with an SQL Clause

 
Sub GetRecords_WithSQLWhere()
   Dim conn As ADODB.Connection
   Dim myRecordset As ADODB.Recordset
   Dim strSQL As String

   strSQL = "Select * from Employees Where IsNull(Region) OR TitleOfCourtesy = 'Mrs.' "

   Set conn = New ADODB.Connection
   conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & CurrentProject.Path & "\mydb.mdb"

   Set myRecordset = New ADODB.Recordset
   myRecordset.Open strSQL, conn, adOpenKeyset, adLockOptimistic
   MsgBox "Selected " & myRecordset.RecordCount & " records."

   myRecordset.Close
   Set myRecordset = Nothing
   conn.Close
   Set conn = Nothing
End Sub



 








Related examples in the same category

1.Use Recordset filter
2.Get result set by column name
3.Filtering Records Using the Filter Property
4.Get the number of recorders which meet the criteria
5.Filtering a Recordset
6.Filtering a Recordset by using the Date type field