Show in a listbox a query filtered by 2 or more textboxes (1 Viewer)

Batraul

Registered User.
Local time
Today, 22:58
Joined
Dec 15, 2014
Messages
13
Hi all!

I'm a newbie in access a wanted to do some start with programming.
I've created a form with two textboxes and a listbox. What I want to do is to show in the listbox the registers filtered by the 2 textboxes. But I would like that the listbox refreshes while typping in the textboxes.

It was no problem to do filtering with only one textbox. The rowsource of the listbox is a query in which I set in the criteria Like [Forms]![Form1]![Textbox1].[Text] & "*"
Then I write the code for the change event of the Textbox1:

Private Sub Textbox1_Change()
Listbox1.Requery
End Sub



With this I have no problem. The problem is when using the 2 textboxes. I write the same in the criteria, Like [Forms]![Form1]![Textbox2].[Text] & "*", on another field but it doesn't work.
I also write the code for the second textbox:

Private Sub Textbox2_Change()
Listbox1.Requery
End Sub


The listbox doesn't filter with both textboxes. When you type in one of them, the listbox filters from it, but when you type in the other textbox, the listbox shows the whole table filtered with the characters of the second textbox.

What am I doing wrong?

Thank you in advance.

Regards.
 

CazB

Registered User.
Local time
Today, 21:58
Joined
Jul 17, 2013
Messages
309
How do you want the criteria to work? should it match either one or the other, or should it match both?
 

Batraul

Registered User.
Local time
Today, 22:58
Joined
Dec 15, 2014
Messages
13
How do you want the criteria to work? should it match either one or the other, or should it match both?

Hi CazB.

Thank you very much for your answer.
The criteria must match both of them.

Thanks again.
 

CazB

Registered User.
Local time
Today, 21:58
Joined
Jul 17, 2013
Messages
309
can you post up a (zipped) sample of what you're trying to achieve?
 

Batraul

Registered User.
Local time
Today, 22:58
Joined
Dec 15, 2014
Messages
13
Off course!

Here you have.

Thank you.
 

Attachments

  • Listbox query.zip
    285 KB · Views: 70

CazB

Registered User.
Local time
Today, 21:58
Joined
Jul 17, 2013
Messages
309
hmm, ok, I see your problem!

In actual use, would all the fields be unbound like this?
 

Batraul

Registered User.
Local time
Today, 22:58
Joined
Dec 15, 2014
Messages
13
I'm sorry. I don't know if I understand properly what you mean about "unbound fields".
If you mean that there are some fields created which don't appear in the query the answer is yes.
The final purporse should be to create a multiple-field search with all the fields in the table and to show in the listbox the query with a multiple-criteria of all the files.
I enclose a picture of another program which makes exactly the same.
The database can have thousands and thousands of registers but, in the case of the picture as an example, it is filtered by 3 criterias (and in all criteria the event is while you type, on change event):
- Item code: it shows all registers that starts by letter "e".
- Diameter (ØD): it also shows all registers that the diameter is exactly "2".
- ln: it also shows all registers that this parameter is greater than "20".

Off course, I wanted to start more easily, only with 2 criterias.

I hope it will help.

Thank you.
 

Attachments

  • Capture.GIF
    Capture.GIF
    95.4 KB · Views: 87
Last edited:

Batraul

Registered User.
Local time
Today, 22:58
Joined
Dec 15, 2014
Messages
13
hmm, ok, I see your problem!

In actual use, would all the fields be unbound like this?

Dear CazB,

I don't want to disturb. Did you tried anything?

Thank you.
 

JHB

Have been here a while
Local time
Today, 22:58
Joined
Jun 17, 2012
Messages
7,732
Try it now.
 

Attachments

  • Listbox query.zip
    92.3 KB · Views: 77

JHB

Have been here a while
Local time
Today, 22:58
Joined
Jun 17, 2012
Messages
7,732
You're welcome, luck with your project.
 

Users who are viewing this thread

Top Bottom