Help! What's wrong with the code?

G

GZ

Dim cnn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim strSQL As String

Set cnn = CurrentProject.Connection
Set rs = New ADODB.Recordset
strSQL = "Select * from Students where LName like '*Tom*' Or FName like
'*Tom*'"
rs.ActiveConnection = cnn
rs.ActiveConnection.CursorLocation = adUseClient
rs.Open strSQL, , adOpenDynamic, adLockOptimistic
msgbox rs.RecordCount


Hi, if I set
strSQL = "Select * from students"
Then the RecordCount returns correct number. But if run the above code, the
RecordCount returns 0.
But there are do many Toms in the Students table, and the same code strSQL =
"Select * from Students where LName like '*Tom*' Or FName like '*Tom*'"
returns correct number on that form (which uses Me.RecordSource = strSQL).
However, this form is created from blank, so there is no Me.RecordSource
set.
What 's wrong?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top