HandsOn Filtering Records with an SQL Clause

1. In the Code window, enter the GetRecords_WithSQLWhere procedure as shown below.

Sub GetRecords_WithSQLWhere() Dim conn As ADODB.Connection Dim rst 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 & _ "\Northwind.mdb"

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

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

0 0

Post a comment