Search function within listbox (1 Viewer)

Onlylonely

Registered User.
Local time
Tomorrow, 00:11
Joined
Jan 18, 2017
Messages
43
Hi,

I'm facing an issue to find the text in the listbox.
Could anyone help me on this?

Below coding is find the text in the table.

Code:
Private Sub txtfind_Change()

        
        Dim strSource As String
        strSource = "SELECT * " & _
         "FROM Guests " & _
         "Where FirstName Like '*" & Me.txtfind.Text & "*';"
         
        Me.List0.RowSource = strSource


End Sub
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 09:11
Joined
Aug 30, 2003
Messages
36,133
What is the issue?
 

Onlylonely

Registered User.
Local time
Tomorrow, 00:11
Joined
Jan 18, 2017
Messages
43
What is the issue?

Objective: I need to get a textbox to filter the Part Number i want in listbox.

Listbox only will show up "OPEN" item in the table.

For example:
When i typing "2" in the textbox. I wish to filter PartNumber 2 in the listbox.
 

Attachments

  • TABLE.JPG
    TABLE.JPG
    39.3 KB · Views: 61

MajP

You've got your good things, and you've got mine.
Local time
Today, 12:11
Joined
May 21, 2018
Messages
8,605
Untested, but likely something like
Code:
Private Sub txtfind_AfterUpdate()
  'Never filter on change event unless you want to filter on each keystroke
   dim lst as access.listbox
   dim strSql as string
   dim strCriteria as string
   dim strOrder as string
   setLst = Me.YourListBoxName
   strSql = "Select PartNumber, Quantity, Rejection from SomeTable"
   
   If not trim(me.QuantityTextBoxName & " ") = "" then
      strSql = StrSql & " WHERE Quantity = " & me.QuantityTextBoxName & " AND Remark = 'Open'"      
   end if
   strOrder = " ORDER BY SomeField1, SomeField2"
   strSql = strSql & strOrder
   debug.print strSql ' double check the string looks good
   lst.rowsource = strSql 
End Sub
 
Last edited:

Orthodox Dave

Home Developer
Local time
Today, 17:11
Joined
Apr 13, 2017
Messages
218
I think you need to requery the list box after your code:
Code:
Private Sub txtfind_Change()

        
        Dim strSource As String
        strSource = "SELECT * " & _
         "FROM Guests " & _
         "Where FirstName Like '*" & Me.txtfind.Text & "*';"
         
        Me.List0.RowSource = strSource

[B][COLOR="Red"]Me.List0.Requery[/COLOR][/B]

End Sub
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 12:11
Joined
May 21, 2018
Messages
8,605
I think you need to requery the list box after your code
No. Setting the rowsource automatically requeries. Even this will requery

me.SomeControl.rowsource = me.somecontrol.rowsource
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 00:11
Joined
May 7, 2009
Messages
19,246
Code:
Private Sub txtfind_Change()

        
        Dim strSource As String
        strSource = "SELECT [Part Number], [Quantity], [Rejection]  " & _
         "FROM yourTable " & _
         "Where ([Part Number] & '') Like '*" & Me.txtfind & "*' And " & _
         "[Remark]='Open';"
         
        Me.List0.RowSource = strSource


End Sub

substitute Real tablename to yourtable.
 

Users who are viewing this thread

Top Bottom