vb
Private Sub FindStr()
Dim strSQL As String
Dim resItem2 As ListItem
Dim recTempDialog As Recordset
lvRes.ListItems.Clear
strSQL = "select * from tblAgencyInfo where AGENCY_NAME LIKE '" & txtSearch & "*';"
Set recTempDialog = myConn.Execute(strSQL)
If recTempDialog.RecordCount <> 0 Then
Do Until recTempDialog.EOF
If Not IsNull(recTempDialog![AGENCY_NAME]) Then
Set resItem2 = lvRes.ListItems.Add(, , recTempDialog.Fields("AGENCY_NAME"))
Else
lvRes.ListItems.Add ""
End If
recTempDialog.MoveNext
Loop
Else
MsgBox "There are No Agencies." & txtSearch.Text, vbInformation
End If
lvRes.Enabled = True
End Sub
Private Sub command1_click()
FindStr
End Sub
' base from your code i've learn that you want to type first all the character of an agency and if you click on something this will process the search criteria. So i change the txt_change to comman button. And in searching you have to check first if the value you entered in the text match to the record in the database, now in checking the record you have to use an if statement and here you use the recordcount property. I add something there which is to check if the recordcount is not equal to zero, meaning to say if the recordcount count is not = to 0 the where clause finds a record and the database. I ommited the movefirst function because you already pointed the search value using the clause.
You can also use Filter in searching record. this is how to use it..
vb
Private sub txtSearch_Change()
if txtsearch.text <> "" then
recTempDialog.filter ="AGENCY_NAME Like ' " & txtSearch & "*'"
else
recTempDialog.Filter ="AGENCY_NAME <> ' ' "
end if
End sub