SQL with where clause
Sub MyFirstConnection()
Dim myConnection As ADODB.Connection
Dim myRecordset As ADODB.Recordset
Dim strSQL As String
Dim strSearch As String
strSearch = "Joe"
strSQL = "SELECT txtCustFirstName, txtCustLastName FROM tblCustomer" & _
" WHERE txtCustLastName = " & " '" & strSearch & "'"
Set myConnection = CurrentProject.Connection
Set myRecordset = New ADODB.Recordset
myRecordset.Open strSQL, myConnection
Do Until myRecordset.EOF
Debug.Print myRecordset.Fields("txtCustFirstName"), _
myRecordset.Fields("txtCustLastName")
myRecordset.MoveNext
Loop
myRecordset.Close
myConnection.Close
Set myConnection = Nothing
Set myRecordset = Nothing
End Sub
Related examples in the same category