Search as you type

Acke

Registered User.
Local time
Today, 01:46
Joined
Jul 1, 2006
Messages
158
Hi!

I want to use TextBox to populate data in the ListBox as user types data in the TextBox.

I made SQL to use as RowSource for the ListBox and it works fine if I use CommandButton to triger the event. Since I want as-you-type event, I tried to use On Key Up or On Change properties, in TextBox, to triger the event. It is not working.

Can you please help?

Code:
Dim st as String

st = "SELECT ID.db, CompanyName.db "
st = st & "FROM db WHERE (((DB.[CompanyName]) Like '*'&[TextBox]&'*'));"

ListBox.RowSource = st

---- above is not the actual code, but you will get the point and it works if I trigger the event by CommandButton----

I even tried to use:

ListBox.Requery
 
I am always impressed by response speed on this forum. Thank you for that!

My original code is as follows:

Private Sub CtrPretraga_KeyUp(KeyCode As Integer, Shift As Integer)
Dim st As String
Dim st As String

st = "SELECT KomitentiDB.IdKomitenta, [NazivFirme] & ' ' & [grad] AS Komitent, KomitentiDB.[Vrednost kupca], "
st = st & "KomitentiDB.[Prodajna faza], KomitentiDB.[Kategorija komitenta] "
st = st & "FROM GradoviDB INNER JOIN KomitentiDB ON GradoviDB.IdGrada = KomitentiDB.IdGrada "
st = st & "WHERE ((([NazivFirme] & ' ' & [grad]) Like '*'&[CtrPretraga]&'*') AND ((KomitentiDB.[Prodajna faza])=0) "
st = st & "AND ((KomitentiDB.[Kategorija komitenta])=[listkategorija])) "
st = st & "ORDER BY GradoviDB.Grad, KomitentiDB.NazivFirme;"

ListPotencijalni.RowSource = st

End Sub

If I trigger this code by CommandButton, it works as I want. Data in the ListBox "ListPotencijalni" filters according to string in the TextBox "CtrPretraga". Now I want to avoid using CommandButton. I would like to trigger the event as user types the string. On Key Up for example
 

Users who are viewing this thread

Back
Top Bottom