|
-
Nov 25th, 2005, 02:23 AM
#1
Thread Starter
New Member
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
-
Nov 25th, 2005, 02:29 AM
#2
Fanatic Member
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:
Dim s as string
s = dtData1.Recordset("Name") & ", " & dtData1.Recordset("Address") & " AND " & dtData1.Recordset("phone number")
Listbox1.AddItem s
r0ach™
Don't forget to rate the post
-
Nov 25th, 2005, 06:34 AM
#3
Thread Starter
New Member
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...
-
Nov 25th, 2005, 06:40 AM
#4
Fanatic Member
Re: Need some help
I'm not sure what the dtSearchSupport object is, but look for a .Filter method.
something like this:
VB Code:
dtSearchSupport.Recordset.Filter = "Name = '" & strName & "' And Lastname = '" & strLastname & "'"
If you're using a QueryString, only return the records that match.
VB Code:
strSQL = "SELECT * FROM table WHERE name = '" & strName & "' AND Lastname = '" & strLastname & "'"
r0ach™
Don't forget to rate the post
-
Nov 25th, 2005, 07:29 AM
#5
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.
-
Nov 25th, 2005, 08:09 AM
#6
Thread Starter
New Member
Re: Need some help
dtSearchSupport is a data source in Microsoft Visual Basic 6.0
-
Nov 25th, 2005, 11:48 AM
#7
Re: Need some help
Post all of the code that performs the search and loads the listbox.
-
Nov 30th, 2005, 04:19 AM
#8
Thread Starter
New Member
Re: Need some help
This is how it looks right now.
VB Code:
Dim strSearchstring as String
Dim strResult as String
Dim intRecordCount as Integer
Dim i as Integer
lstResult.Clear
strSearchstring = txtText
dtSearchSupport.RecordSet.MoveLast
dtSearchSupport.RecordSet.MoveFirst
intRecordCount = dtSearchSupport.RecordSet.RecordCount
strResult = dtSearchSupport.RecordSet.FindFirst ("Name='" & strSearchString & "'")
If dtSearchSupport.RecordSet.NoMatch Then
lstResult.AddItem "No posts were found"
Exit Sub
End If
Do Until i = intRecordCount
strResult = dtSearchSupport.RecordSet.FindNext ("Name='" & strSearchString & "'")
If dtSearchSupport.RecordSet.NoMatch Then
lstResult.AddItem "End of posts"
End If
lstResult.AddItem strResult
i = i + 1
Loop
But I get an errormsg on .FindFirst that says:
Compile error:
Expected Function or Variable
-
Nov 30th, 2005, 10:26 AM
#9
Re: Need some help
What kind of data controls are you using?
DAO or ADO?
-
Nov 30th, 2005, 11:28 AM
#10
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|