Results 1 to 10 of 10

Thread: Need some help

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2005
    Posts
    5

    Need some help

    I have a form with five radio buttons.
    When I choose e.g. Name, I write the name I want to search for in a textbox and I click on my button Search.
    A search is made in my database, however, the search returns ALL posts in the database into my listbox.

    Q1:How can I make the search for the specific word in the textbox and show the result in the listbox?

    Q2:How do I get more than just the Name in the listbox? I want e.g. Name, Adress AND phone number.

    Code for the search is:
    dtData1.Recordset.Findfirst "Name='" & strSearchString & "'"

    /The_spike

  2. #2
    Fanatic Member r0ach's Avatar
    Join Date
    Dec 1999
    Location
    South Africa
    Posts
    722

    Re: Need some help

    A1:Loop through the recordset, and place each record's result in the listbox
    A2:You could build as string with the results:
    VB Code:
    1. Dim s as string
    2. s = dtData1.Recordset("Name") & ", " & dtData1.Recordset("Address") & " AND " & dtData1.Recordset("phone number")
    3. Listbox1.AddItem s

    r0ach™
    Don't forget to rate the post

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 2005
    Posts
    5

    Re: Need some help

    Thanks...

    BUT, How do I get just the name I want?
    For instance, if I search for Mark Hudson, I only want Mark Hudson to show in the listbox...

    This is my code now:

    If boolName Then
    strSearchString = txtSearchString
    s = dtSearchSupport.Recordset("Name") & "," & dtSearchSupport.Recordset("Arrend")
    lstSupportSearch.AddItem s
    end if

    With a loop ofcourse...
    But still I get Mark Hudson AND the other posts...

  4. #4
    Fanatic Member r0ach's Avatar
    Join Date
    Dec 1999
    Location
    South Africa
    Posts
    722

    Re: Need some help

    I'm not sure what the dtSearchSupport object is, but look for a .Filter method.
    something like this:
    VB Code:
    1. dtSearchSupport.Recordset.Filter = "Name = '" & strName & "' And Lastname = '" & strLastname & "'"
    If you're using a QueryString, only return the records that match.
    VB Code:
    1. strSQL = "SELECT * FROM table WHERE name = '" & strName & "' AND Lastname = '" & strLastname & "'"

    r0ach™
    Don't forget to rate the post

  5. #5
    PowerPoster Keithuk's Avatar
    Join Date
    Jan 2004
    Location
    Staffordshire, England
    Posts
    2,236

    Re: Need some help

    dtSearchSupport is a Data control. He's using the old method.
    Keith

    I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.

  6. #6

    Thread Starter
    New Member
    Join Date
    Nov 2005
    Posts
    5

    Re: Need some help

    dtSearchSupport is a data source in Microsoft Visual Basic 6.0

  7. #7
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Need some help

    Post all of the code that performs the search and loads the listbox.

  8. #8

    Thread Starter
    New Member
    Join Date
    Nov 2005
    Posts
    5

    Re: Need some help

    This is how it looks right now.

    VB Code:
    1. Dim strSearchstring as String
    2. Dim strResult as String
    3. Dim intRecordCount as Integer
    4. Dim i as Integer
    5.  
    6. lstResult.Clear
    7.  
    8. strSearchstring = txtText
    9.  
    10. dtSearchSupport.RecordSet.MoveLast
    11. dtSearchSupport.RecordSet.MoveFirst
    12. intRecordCount = dtSearchSupport.RecordSet.RecordCount
    13.  
    14. strResult = dtSearchSupport.RecordSet.FindFirst ("Name='" & strSearchString & "'")
    15.  
    16. If dtSearchSupport.RecordSet.NoMatch Then
    17. lstResult.AddItem "No posts were found"
    18. Exit Sub
    19. End If
    20.  
    21. Do Until i = intRecordCount
    22. strResult = dtSearchSupport.RecordSet.FindNext ("Name='" & strSearchString & "'")
    23. If dtSearchSupport.RecordSet.NoMatch Then
    24. lstResult.AddItem "End of posts"
    25. End If
    26. lstResult.AddItem strResult
    27. i = i + 1
    28. Loop

    But I get an errormsg on .FindFirst that says:

    Compile error:
    Expected Function or Variable

  9. #9
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Need some help

    What kind of data controls are you using?

    DAO or ADO?

  10. #10
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Need some help

    FindFirst and the other find methods are not functions.

    Change these lines

    strResult = dtSearchSupport.RecordSet.FindFirst ("Name='" & strSearchString & "'")

    to

    Call dtSearchSupport.RecordSet.FindFirst ("Name='" & strSearchString & "'")
    or

    dtSearchSupport.RecordSet.FindFirst "Name='" & strSearchString & "'"

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