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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Like* statement not working

Status
Not open for further replies.

SchuhTL

Technical User
Dec 19, 2001
36
US
I am trying to use a like statement with no success. Here is what I am doing:

Dim ObjRS
Dim StrSQL
Dim varLocation
varLocation = Request.Form("location")
Set objRS = Server.CreateObject("ADODB.Recordset")
StrSQL = "SELECT LOCATION, REGION1, SITE_CATEGORY, SITE_CATEGORY_2 FROM "
StrSQL = StrSQL & "REGION WHERE LOCATION LIKE ('" & varLocation & "*')"

I can write this query to the screen - copy and paste it into access and it works great and it does return records. If I remove the LIKE statement in the WHERE clause and replace with LOCATION = ('" & varLocation & "')" it will work as long as varLocation has a exact match in the database? I need for the user to be able to enter a "location"/mailstop. A complete mailstop is 10 characters(FLTBAC0101). If the user enters FLTB I need the recordset to return all values like FLTB(Florida, Tampa Bay), if the user enters FL, I need the recordset to return all mailstops in FL(Florida). What I am I doing wrong?
 
Access uses % instead of *. Try this:


StrSQL = "SELECT LOCATION, REGION1, SITE_CATEGORY, SITE_CATEGORY_2 FROM "

StrSQL = StrSQL & "REGION WHERE LOCATION LIKE ('" & varLocation & "%')"
-Ovatvvon :-Q
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top