Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with Like Statement. 1

Status
Not open for further replies.

titans514

Programmer
Dec 4, 2002
13
0
0
US
Hi, I am new to programming and I was wondering if anybody could help me with a LIKE statement to return values for LastName and FirstName.

I tried the following, but it did not work.
ME.LIST0.ROWSOURCE = "SELECT * FROM TABLE WHERE FIELD LIKE '" & ME.TEXT0 & "'"

I tried it several different ways and I tried the wildcard characters, but to no avail. Any help would be great.
 
I'm assuming that you're replacing the TABLE and FIELD in your SQL statement with the required table and field names.

add a text box to your form called txtLike
add a list box called lstList
add a comand button

Try some of these replacing your field and table names for mine by putting one of them in the click event of your command button.

This will return all Names containing the text in txtLike

Me.lstList.RowSource = "SELECT NameID, Name FROM tblName WHERE Name LIKE '*" & txtLike & "*'"

This will return all Names ending with the text in txtLike

Me.lstList.RowSource = "SELECT NameID, Name FROM tblName WHERE Name LIKE '*" & txtLike & "'"

This will return all Names starting with the text in txtLike

Me.lstList.RowSource = "SELECT NameID, Name FROM tblName WHERE Name LIKE '" & txtLike & "*'"

There are two ways to write error-free programs; only the third one works.
 
That was it, could not get down the quotes in the right spot. Thanks a bunch.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top