Search strings within a listbox?

sailorguy

Registered User.
Local time
Yesterday, 21:53
Joined
Jan 31, 2008
Messages
48
Hi,

It seems searching is a common question, but I haven't seen what I'm looking for exactly.

I have an unbound listbox which displays over 200 records with various strings. I want to search the entire list box and find the matching value as entered in a textbox on the form. I basically want the standard "Find" function but to search inside a listbox.

Is there a way to do this?
 
Try the following in your Query criteria;
Code:
Like "*" & Me.YourTextBoxName & "*"
 
Hi,

I'm not sure that's what I want. I apologize for a poor description, as I'm still a newbie. My form is using the listbox to display "completed" records. Currently I have code that allows me to double-click any of the lines to open a different form to edit that record.

The trouble is with over 200 records it's hard to find the line I want to select by scrolling along. I would like to have a "find" button on this same main form, that will search the listbox that's populated, and highlight that row so I can double-click it.

Does that make sense?
 
Hi Booty,

I had read that when I was searching, but again this looks like it uses a query to search for the string. What I have is a listbox already populated on a form, which I want to search.

Maybe I don't understand quite what that solution is doing.

Thanks!
 
The solution I linked to in my previous post, has a Listbox that is populated by a query. Initially the query selects ALL records, as the user types into the text box, the query is set up to search any number of fields in the list box for matches against what has been typed into the text box. Gradually whitelling down the number of matches as the search criteria is being typed into the text box.

You can then us the Listbox's On Double click event to open specific records once they have been located.
 
Hi Booty,

You are right...I didn't quite understand at first, but this does EXACTLY what I want. It works great!

One additional thing I would like is a little button beside the search box to clear the "filter". What would be involved in this?
 
Maybe this question would help. What is the value of your listbox when it's showing ALL records?
 
Hi Booty,

You are right...I didn't quite understand at first, but this does EXACTLY what I want. It works great!

One additional thing I would like is a little button beside the search box to clear the "filter". What would be involved in this?

You simply need a button that sets both the text boxes (one of them is hidden ie. not visible) to a zero length string "" and re-queries the list box, something along the lines of;
Code:
    Me.TextBoxThatIsVisible = ""        [COLOR="SeaGreen"]'Replace [B]TextBoxThatIsVisible[/B] with the name of your visible text box[/COLOR]
    Me.TextBoxThatIsHidden = ""        [COLOR="SeaGreen"]'Replace [B]TextBoxThatIsHidden[/B] with the name of your hidden text box[/COLOR]
    
    Me.ListName.Requery      [COLOR="SeaGreen"]'Replace [B]ListName[/B] with the name of your text box[/COLOR]
IN the on click event of the button
 
Duh, I knew that:-) Stupid me forgot to do it for the hidden field as well. Working perfectly...thanks again!
 

Users who are viewing this thread

Back
Top Bottom