Results 1 to 4 of 4

Thread: [RESOLVED] Finding names using LIKE

Threaded View

  1. #1

    Thread Starter
    Banned Michael_Kamen's Avatar
    Join Date
    May 2001
    Location
    The Netherlands
    Posts
    1,180

    [RESOLVED] Finding names using LIKE

    Hi,

    I'm using this code to list all names from a table into a listbox:
    VB Code:
    1. Dim path As String
    2. Dim strQuery As String
    3. Dim i As Integer
    4. Dim r As Integer
    5. path = App.path & "\persons.mdb"
    6. Set db = OpenDatabase(path)
    7. strQuery = "SELECT * FROM Names where Name Like '" & txtSearch.Text & "*'"
    8. Set rs = db.OpenRecordset(strQuery, dbOpenDynaset)
    9. r = rs.RecordCount
    10. If r <> 0 Then
    11. List1.Clear
    12. For i = 0 To r
    13. List1.AddItem rs.Fields("Name").Value
    14. rs.MoveNext
    15. Next
    16. End If
    17. rs.Close
    18. End Sub
    The code above is run in the change event of my search textbox.
    Say I have two usernames in the table: "Pete" and "Peter".
    It works fine if I type like "Pe" or "Pet" or "Pete", they are listed in the listbox. But as soon as I type "Peter" I get the error "No current Record".
    What am I doing wrong?
    Last edited by Michael_Kamen; Oct 13th, 2002 at 12:50 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width