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
|