Searchbox VBA problem

Gaztry80

Member
Local time
Today, 22:10
Joined
Aug 13, 2022
Messages
62
Good evening,

I have a form which contains a combox to select certain products. I use the combobox to fill in the form. This combobox is based on a qry with approx 50 records.
Now, I wanted to make a search box in the form which can be used to filter the combobox so I don't have to scroll all the way and look for the product.
Therefore, I have created a text box with button and placed the below vba code on the clicking event".

Code:
Private Sub btnSearch_Click()

    Dim SQL As String
    
    SQL = "SELECT qryProductChooser.ProdID, qryProductChooser.[Productname], qryProductChooser.Category FROM qryProductChooser" _
    & "WHERE Category LIKE  '*" & Me.txtKeywords & "*' "
            
    Me.txtProductChooser.RowSourceType = "table/Query"
    
    Me.txtProductChooser.RowSource = "SQL"
    Me.txtProductChooser.Requery
        

End Sub

However, when I do this the combobox gets empty.
When I for example make a seperate QRY as example and put the Me.txtProductChooser.RowSource directly to the saved QRY it shows exactly what I want.
Can somebody explain to me what is going wrong? If additional information is needed, please let me know 😅 Already many thanks!
 
untested: Try remove the quotes from "SQL"

Me.txtProductChooser.RowSource = "SQL"
to
Me.txtProductChooser.RowSource = SQL
 
Hi. You shouldn't need an extra textbox to filter the combobox, you should be able to do it from the combobox itself. Check out Allen Browne's example for filtering a combobox.
 

Users who are viewing this thread

Back
Top Bottom