How do you create a text box search function on a form?

W

Widge

I've got a listbox which is pulling up:

Merchant
Merchant Code
Description
Price

and what I would like to do is have a textbox drive what the listbox
is displaying. Basically I can get the table selection behind the
scenes sorted ok, so I've got a combobox driving where you are
searching "ie Merchant Code/Description", but what I don't know is how
to get the search part of things working.

This is what I have so far :

Private Sub Command13_Click()

If Combo8 = "Description" Then
SQLTab = "AllPrices.Description"
ElseIf Combo8 = "Manufacturer Code" Then
SQLTab = "AllPrices.[Manu Code]"
ElseIf Combo8 = "Merchant Code" Then
SQLTab = "AllPrices.[Product Code]"
End If

List11.RowSource = "SELECT AllProducts.Supplier, AllPrices.
[Product Code], AllPrices.Description, AllPrices.Price, AllPrices.
[Core/Wider] & FROM AllPrices INNER JOIN AllProducts ON AllPrices.
[Product Code] = AllProducts.[Product Code] WHERE " & SQLTab & " Like
'" & Text6 & "'"

Debug.Print List11.RowSource

End Sub

Bit baffled as to why the Like doesn't work. Even when hard coding it
to a *.

Cheers for any help!
 
O

OldPro

I've got a listbox which is pulling up:

Merchant
Merchant Code
Description
Price

and what I would like to do is have a textbox drive what the listbox
is displaying. Basically I can get the table selection behind the
scenes sorted ok, so I've got a combobox driving where you are
searching "ie Merchant Code/Description", but what I don't know is how
to get the search part of things working.

This is what I have so far :

Private Sub Command13_Click()

If Combo8 = "Description" Then
SQLTab = "AllPrices.Description"
ElseIf Combo8 = "Manufacturer Code" Then
SQLTab = "AllPrices.[Manu Code]"
ElseIf Combo8 = "Merchant Code" Then
SQLTab = "AllPrices.[Product Code]"
End If

List11.RowSource = "SELECT AllProducts.Supplier, AllPrices.
[Product Code], AllPrices.Description, AllPrices.Price, AllPrices.
[Core/Wider] & FROM AllPrices INNER JOIN AllProducts ON AllPrices.
[Product Code] = AllProducts.[Product Code] WHERE " & SQLTab & " Like
'" & Text6 & "'"

Debug.Print List11.RowSource

End Sub

Bit baffled as to why the Like doesn't work. Even when hard coding it
to a *.

Cheers for any help!

Text6 defaults to Text6.Value. The .value property will show NULL if
the text hasn't been saved. Could it be that the cursor is still
blinking in the Text6 control, and thus the text hasn't yet been
saved? If so, use Text6.Text instead.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top