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

search on field with different input formats

Status
Not open for further replies.

Lhuffst

Programmer
Jun 23, 2003
503
US
My search form allows users to search on license plate number. Because of vanity plates etc, there isn't a set pattern. Some have spaces, some do not. Since there are several search fields available, I build the sql. Here is the line for the license plate
Code:
 ssql = ssql + " tblParkingPermitVehList.fldLicenseNo = '*" & fldLicenseNo & "*' And "
Note. The and is stripped off if its not needed.

The search works if you put it in exact but if the value isn't stored in the database that way it doesn't return the record.
i.e. fls179 in the database is fls 179. If I enter fls179 on the form, I don't get any records; if I enter it as fls 179 it returns the record.

Since the database values are stored in a variety of ways, I need my sql to find it either way. Thanks lhuffst
 
Don't use "=" since it expects exact match of the values.
Code:
ssql = ssql + " tblParkingPermitVehList.fldLicenseNo Like '*" & fldLicenseNo & "*' And "
Also, do you understand the difference between using "+" and "&"?


Duane
Hook'D on Access
MS Access MVP
 
duane, thanks for the post. First...based on your response, I changed my + to a &..
Second - in the code, I had tried like before and it didn't work but your post make the lightbulb go off. I changed the code to
Code:
ssql = ssql & " tblParkingPermitVehList.fldLicenseNo Like '" & left(fldLicenseNo,3) & "*' And "

My reasoning was that the first 3 digits will always be digits and not spaces. So far the testing works fine.
Thanks for the help.
 

"search on license plate number" and "the first 3 digits will always be digits and not spaces"

If you deal with license plate numbers, you cannot make that assumption. Even if your State (or Country) have the rule of "the first 3 digits will always be digits and not spaces", there always will be visitors from other places (right?) or 'personalized plates'

Have fun.

---- Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top