Searchbox VBA problem (1 Viewer)

Gaztry80

Member
Local time
Today, 22:21
Joined
Aug 13, 2022
Messages
52
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!
 

jdraw

Super Moderator
Staff member
Local time
Today, 16:21
Joined
Jan 23, 2006
Messages
15,379
untested: Try remove the quotes from "SQL"

Me.txtProductChooser.RowSource = "SQL"
to
Me.txtProductChooser.RowSource = SQL
 

theDBguy

I’m here to help
Staff member
Local time
Today, 13:21
Joined
Oct 29, 2018
Messages
21,474
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

Top Bottom