473,385 Members | 1,973 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Access 97: using WHERE ... LIKE to compare user input string

I am trying to write a query that will search the database for a portion of a string that is input by a user.

The field I am looking at sometimes contains dashes, leading zeros, etc. so I want to use the LIKE as a contains because the user does not know exactly how it was entered.

So I want to know if the billnum contains 8836 - it may be entered as 08836, a8836, 8836-a, etc. I can find it if I enter it exactly as it is in the database with the following line:
Expand|Select|Wrap|Line Numbers
  1. WHERE (Claims.BillNum1)=[Forms]![FindProNumber]![BillNumber]
but I can't find a way to have it look for the string in the field. Maybe it can't be done in Access or I have to use VB?
I tried:
Expand|Select|Wrap|Line Numbers
  1. WHERE (Claims.BillNum1) like ‘*[Forms]![FindProNumber]![BillNumber]*’) 
- didn't get a syntax error, but it's not finding my record.
Any help would be greatly appreciated!

Kathy
Aug 27 '13 #1
4 2287
jimatqsi
1,271 Expert 1GB
You could use
Expand|Select|Wrap|Line Numbers
  1. WHERE Instr(Claims.BillNum1,[Forms]![FindProNumber]![BillNumber])>0
That call to Instr will return the character number where the string begins if it is in the searched string; or it returns zero if it's not.

Jim
Aug 27 '13 #2
zmbd
5,501 Expert Mod 4TB
The wildcard will be your friend and you ALMOST have it here:
WHERE (Claims.BillNum1) like ‘*[Forms]![FindProNumber]![BillNumber]*’)
issues:
  1. the "smart" single quote, you can't use these in the SQL these need to be the normal " ' " dumb-style.
  2. the extra quote shouldn’t be needed at all using the “Like” comparator.
  3. the name of the control is being returned, not the value.
So instead of the expected:
WHERE (Claims.BillNum1) like *ControlValue_String*)
the string being returned is:
WHERE (Claims.BillNum1) like ‘*[Forms]![FindProNumber]![BillNumber]*’)


So try this little tweak (note this is air code):
WHERE ((Claims.BillNum1) Like "*" & [Forms]![FindProNumber]![BillNumber] & "*")
Note: no single or extra double quote and the placement of the ampersand ( & ) and the remaining portion of the SQL/code.

Be careful with the wildcard... if the "*" throws an error then you maybe using the alternate standard available in access where the "%" sign is used instead. I don’t remember which version; however, MS went from DAO to ADO and then back again and the ADO uses the "%" sign:
Access wildcard character reference. So if you get an error you should know how to fix it :)
Aug 27 '13 #3
zmbd
5,501 Expert Mod 4TB
Looks like I cross posted just a little...
For most applications, I would avoid using the INSTR() function over the "Like" operator. Generally, I avoid all functions in SQL if there is an operator that performs the same or similar action on the data.
The function requires that the VBA environment is available whereas the operator is part of the SQL engine.

In any case the search may take a long time as the database grows.

Here's a link for that covers the three most common ways of searching within string:
ACC: How to Search for Characters or Strings in Records
Aug 27 '13 #4
omg - it worked perfectly! Thank you so much!
Aug 27 '13 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Maxd out | last post by:
Hi all As a newbie to C++ just wondering if you can compare a user input e.g. the integer 2 to see if that integer is contained within a parameter list. If so how can it be done and can it be...
1
by: amitbadgi | last post by:
Welcome back amitbadgi | Logout | Faq Knowledge Discovery Keys COMPUTER PROGRAMMING, DATA MINING, STATISTICS, ARTIFICIAL INTELLIGENCE * Settings * Photos * Lists * MVPs * Forums * Blogs
4
by: bazzer | last post by:
i m trying to compare a time i have stored in a session variable, to a time of day: If (Session("theShowTime") < 18.0) Then .... basically i want to know if the time is before or after 6pm....
2
by: Matt | last post by:
Hi, I'm ridiculously new to Access (about a week!) so please be patient! My database is a record of British Standards. Each has a unique identifier. Some are split into parts. I would like...
2
by: wertqt | last post by:
hi there, im having a slight problem in matching the user input(textbox's text) with the values in one of the columns from a MS Access database. Im using C#.NET. The situation is this : My...
3
by: mattmao | last post by:
Hello everyone. This question is regarding ISBN number checking. I've done it with my own algorithm, which is pretty bad in consideration about the total lines of code. Now I want to improve...
7
by: clickingwires | last post by:
This might be really simple but for the life of me I cannot get this to work. What I am trying to do is use a table with one field as a password. I however cannot connect to it from a module to...
14
by: jld730 | last post by:
All, I will have a user input a string that is either 10, 14, 17 characters long, or contains a comma (of any length). The script proceeds from there depending on the length entered. When I test...
2
by: curien | last post by:
Hello, I am working on a code that takes the users input ( a string of digits) from the command line and prints out the median number. I am trying to accomplish this by: from sys import argv ...
1
by: golnaz hgh | last post by:
the xml file is like this: <publist> <book> A book entry has the following fields: o Title; o One or more authors; o Publisher; o Year </book>
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.