Sort Form from List Box

Infinite

More left to learn.
Local time
Today, 08:50
Joined
Mar 16, 2015
Messages
402
Hello, I have a form named "frmItems" with a list box in it called "lstItems"
I would like to create a find (or search) button for it, any idea how? I also have a search box called "txtSearchI"

What VBA code would I use for that? Thanks!
 
You don't need VBA code to create a button. Just open the form in design view, which opens the "Form Design Tools" contextual ribbon. From there, click the "Design" tab and look for a button in the "Controls" group. Then, drop the button on your form.
 
Drop what button?
 
I believe your question was how to create a button . . .
I would like to create a find (or search) button for it, any idea how?
I have described how I would create a button. So in reply to your second post, "That button."
 
Ok, sorry about taking so long to respond, ive been VERY busy. 1st off, I know what your talking about, but what I want is to create a filter of sorts, that filters the query because I get the info for the list box from the query, so, by filtering the query im "searching" for it, in a sense of thinking. So, now that you know that, how would you do that?
 
1. Create a text box to use as your filter
2. Open your query that is tied to your list box.
3. Tie the field to your text box which will act like a filter... Like [Forms]![form_name]![text_box_name] & "*"
4. Go back to your text box and add code On Change event or After Update.
5. On your vba refresh your list box using this : list_name.Requery

And your done. The list box will update depending on what you type on your textbox, which acts like a filter for your listbox/query.

:)
 
ok, 1st, Thanks a TON! 2nd, how would I make it so has a type it, it updates it? I cant see to find how to do that.
 
ok, 1st, Thanks a TON! 2nd, how would I make it so has a type it, it updates it? I cant see to find how to do that.

You have to do a On change event on your textbox.

add this code on that event list_name.Requery
 
ya, I keep trying that, and it doesnt work...
 
you mean me.list.requery? Not form, correct? I tried form name and it error-ed.
 
I also did it with list, and it searched once, as I typed, but only for the first letter.
 
It errors,
Code:
Compile Error:

 Method or data member not found
 
And this is my code

Code:
Private Sub txtSearchI_Change()
Me.lstItems.Requery
Me.frmItems.Requery
End Sub
 
Ok lets go back and make it easier. I say just keep the text box and add a button on the side.
Code:
 me.lstitems.requery

Add this code to your button on event On click.

This should do the trick. The list will update only when the user clicks on the button.
 
I have that already. But, I just wanted it to update as I typed.
 
Ok, I have that working (thanks to MarkK and Fernando) but, when I use it in a navigation form ( have the frmItems or tblEvents in a navigation form), it doesnt work. Any ideas why it would do it?

Also, How can I make it so that it searches for anything, so if I have items 1a, and 2a, if I search for A, it gives me both records instead of none, because none of them start with A.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom