how to filter a listbox

sven2

Registered User.
Local time
Today, 10:29
Joined
Apr 28, 2007
Messages
297
Hello,

I am trying to filter a listbox with rhe folowing code:

strSQL = " SELECT KlantID, Klantnaam, Actief " & _
" FROM TblOpzoekenKlanten " & _
" WHERE (((TblOpzoekenKlanten.klantnaam) Like '*(me.txtzoeken.value)*' )"
Me.lstklanten.RowSource = strSQL

But this doesn't do anything at all ...
What is wrong with this code?

Before I forget to mention:
it is an adp project connected with sql server.

Thanks in advance,
Sven.
 
Last edited:
Add one line after your code

Me.lstklanten.requery



Khawar
 
Hello,

I have made the change, but even then it is not working. I get no error but the list is always empty when I fill something in ...

strSQL = " SELECT KlantID, Klantnaam, Actief " & _
" FROM TblOpzoekenKlanten " & _
" WHERE (((TblOpzoekenKlanten.klantnaam) Like '*(me.txtzoeken.value)*' )"
Me.lstklanten.RowSource = strSQL
Me.lstklanten.Requery

Sven.
 
change the line as below

" WHERE (((TblOpzoekenKlanten.klantnaam) Like '*' " & me.txtzoeken.value & "'*' )"

and tell me is it working now




Khawar
 
Hello,

no, it isn't working.
the msgbox is showing the following (see attachment).

Sven.
 

Attachments

  • error.jpg
    error.jpg
    13.1 KB · Views: 121
try this

" WHERE (((TblOpzoekenKlanten.klantnaam) Like '*''" & me.txtzoeken.value & "''*' )"
 
It's about you quotes marks I think Sven - try this

WHERE TblOpzoekenKlanten.klantnaam Like " & Chr$(34) & "*" & me.txtzoeken.value & "*" & Chr$(34)

I try to use Chr$(34) when putting the quotes in the string to keep them distinct from the double quotes delimiting the string.

Hope this helps.
 

Users who are viewing this thread

Back
Top Bottom