EOF always false with wildcard
I am having a problem with a recordset. When I do a query that uses the LIKE operator and the % wildcard, then cycle through the resulting recordset to add the records to a list box, EOF never becomes true. It will add the records, but never reach EOF. If I don't use the LIKE operator with the wildcard, it cycles through the recordset just fine and ends. What is going on?
Here is the code:
'Declare cnnGetHits
Dim cnnGetHits As ADODB.Connection
'Declare rstGetHits
Dim rstGetHits As ADODB.Recordset
'Set cnnGetHits to a new connection
Set cnnGetHits = New ADODB.Connection
'Set rstGetHits to a new recordset
Set rstGetHits = New ADODB.Recordset
'Create the SQL statement
'SQL = "SELECT * FROM tblAttenders " & _
"WHERE Ucase$(LastName) like '" & strLastName & "%'"
'Open cnnGetHits
cnnGetHits.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source='c:\church.mdb'"
'Open rstGetHits
rstGetHits.Open SQL, cnnGetHits, adOpenKeyset, adLockOptimistic
with rstGetHits
'Move to the first record
.MoveFirst
'Loop through the record
Do Until .EOF
'Add the item
lstHits.AddItem !LastName & " " & !FirstName
'Move to the next record
.MoveNext
Loop
End With
|