ListBox and SQL

Shady Baby

New member
Local time
Today, 17:31
Joined
Jun 24, 2008
Messages
6
RESOLVED

Hi,
I'm having a problem with a SQL Statment.

I have a ListBox which has 5 columns filled with text from the table "Test"

Code:
Private Sub cmdNP_Click()
    If IsNull(Me.txtNP) Then
        MsgBox "Missing Text"
    Else
        SQL = "SELECT * FROM Ricoh WHERE ([Ricoh.model] LIKE " & me.txtNP & " '%');"
        Me.lstRicoh.RowSource = SQL
        Me.lstRicoh.Requery
    End If
End Sub
So, the ListBox has hundreds of filled rows from the table "Test", what I want
is when someone introduces, for example "F" on the textbox txtPN
the ListBox only get filled with the data where the field "model"
starts with "F" (the value introduced on the txtbox)

I hope I could explain well. Thanks


SOLUTION

Looks like we don't use percentage (%) on VBA on the LIKE Statment, but asterisks (*)
So, the right statment would be:

Code:
SQL = "SELECT * FROM Ricoh WHERE ([Ricoh.Model] Like '*" & Forms!Ricoh.txtNP & "*');"

 
Last edited:
Problem resolved. Thank you though ,people.
 
Last edited:
Would be nice if you posted what the resolution to your problem was for when the next person searches the forum for a similar issue.
 
OKay.

Looks like we don't use percentage (%) on VBA on the LIKE Statment, but asterisks (*)
So, the right statment would be:

Code:
SQL = "SELECT * FROM Ricoh WHERE ([Ricoh.Model] Like '*" & Forms!Ricoh.txtNP & "*');"
 
Last edited:

Users who are viewing this thread

Back
Top Bottom