473,466 Members | 1,456 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to Use the LIKE operator?

76 New Member
This is done in a DataAccessPage using the microsoft script editor with Access 2003.

Say I use this line to search a field for a matching string.
Expand|Select|Wrap|Line Numbers
  1. rs.find "[Customer NAME] = '" & CStr(InputBox("Please enter customer to find", "Find")) & "'"
That works fine if you know exactly what string you are looking for, but say you only know the first few letters. I tried to use the following line to get find to match wildcards without success. It will work if put the entire matching string in the input box; so "james" will match a recordset james, but the string "jam*s" will not match. Do I have a syntax problem or am I using the wrong function all together?
Expand|Select|Wrap|Line Numbers
  1. rs.find "[Customer NAME] LIKE '" & CStr(InputBox("Please enter customer to find", "Find")) & "'"
This is the entire block of code for the cmdSearch button onclick event.
Expand|Select|Wrap|Line Numbers
  1. <SCRIPT language=vbscript event=onclick for=cmdCustomerSearch>
  2. <!--
  3. ' Clone the recordset.
  4.  
  5. Dim rs
  6. Set rs = MSODSC.DataPages(0).Recordset.Clone
  7. On error resume next
  8.  
  9. 'rs.find "[CUSTOMER NAME]=" & cStr(InputBox("Please enter customer to find", "Find"))&""
  10. rs.find "[Customer NAME] = '" & CStr(InputBox("Please enter customer to find", "Find")) & "'"
  11. ' error handling
  12.  
  13. If (err.number <> 0) Then
  14.     Msgbox "Error: " & err.number & " " & err.description,,"Invalid Search"
  15.     Exit Sub
  16. End If
  17. ' Check search results for success.
  18. If (rs.bof) or (rs.eof) Then
  19.     Msgbox "No Product found",,"Search Done"
  20.     Exit Sub
  21. End If
  22. MSODSC.DataPages(0).Recordset.Bookmark = rs.Bookmark
  23. -->
  24. </SCRIPT>
I've looked everywhere for this information but I can't find anything that deals with user inputted data to know if my syntax is right.

Thank you for any help you may have,
James
Sep 28 '07 #1
17 4215
FishVal
2,653 Recognized Expert Specialist
Hi, James.

Try to enter '%' wildcard instead of '*'.
Sep 28 '07 #2
kcddoorman
76 New Member
I get the same problem. I'm thinking that the rs.find is only getting the string "jam*s" or "jam%s" and trying to match it. It doesn't see that the character % is a wildcard. the search works just fine when I type in "james".

Question. In this line:
Expand|Select|Wrap|Line Numbers
  1. rs.find "[job name] LIKE '" & CStr(InputBox("Please enter a job name to find", "Find")) & "'"
what does the ' character do. It appears after LIKE, like ' " &, and after the last & in between the quotes " ' "

I thought it was how you make a comment, but it is doing something else here.
Sep 28 '07 #3
FishVal
2,653 Recognized Expert Specialist
I get the same problem. I'm thinking that the rs.find is only getting the string "jam*s" or "jam%s" and trying to match it. It doesn't see that the character % is a wildcard. the search works just fine when I type in "james".

Question. In this line:
Expand|Select|Wrap|Line Numbers
  1. rs.find "[job name] LIKE '" & CStr(InputBox("Please enter a job name to find", "Find")) & "'"
what does the ' character do. It appears after LIKE, like ' " &, and after the last & in between the quotes " ' "

I thought it was how you make a comment, but it is doing something else here.
Weird. What is this recordset type? ADO? DAO?
Sep 28 '07 #4
kcddoorman
76 New Member
how do you tell? ADO or DAO I have used pearl to access the database but that doesn't mean anything I guess. ADO means access can access another databases right. I guess it is DAO because its been created and developed locally on one machine.
Sep 28 '07 #5
FishVal
2,653 Recognized Expert Specialist
how do you tell? ADO or DAO I have used pearl to access the database but that doesn't mean anything I guess. ADO means access can access another databases right. I guess it is DAO because its been created and developed locally on one machine.
Ok.

M$ says it is ADO.
Try to use Filter property instead of Find method.
BTW both wildcards work. ;)
Sep 28 '07 #6
NeoPa
32,556 Recognized Expert Moderator MVP
James,

It looks to me like you're using LIKE but without ever putting in the wildcard character. Your code doesn't have either version in there.
Expand|Select|Wrap|Line Numbers
  1. rs.find "[job name] LIKE '" & CStr(InputBox("Please enter a job name to find", "Find")) & "'"
should be
Expand|Select|Wrap|Line Numbers
  1. rs.find "[job name] LIKE '" & CStr(InputBox("Please enter a job name to find", "Find")) & "&'"
Give me a sec & I'll dig up a link to an article that discusses them and how to use them.
Sep 29 '07 #7
NeoPa
32,556 Recognized Expert Moderator MVP
Check out ANSI Standards in String Comparisons
Sep 29 '07 #8
NeoPa
32,556 Recognized Expert Moderator MVP
Maybe I've misunderstood. It just occurred to me that you may be expecting the operator to enter the string with various wildcard characters embedded within it. In that case please ignore my earlier post.
It might be a good idea to use Debug.Print to show the actual line that's created though. This will help you determine exactly what is going wrong and where.
Sep 29 '07 #9
kcddoorman
76 New Member
Expand|Select|Wrap|Line Numbers
  1. rs.find "[job name] LIKE '" & CStr(InputBox("Please enter a job name to find", "Find")) & "&'"
This line of code would assume that the input search string will always have a wildcard after it. So a search for "John" will return not only John but also Johnson or Johnsonville or Johnny Number 5. Right? Or does it not matter.


Ok i just tried this in my code. What it does is append the & character to any string I enter into the textbox. So a search for James is really a search for James&. I'm beginning to think that FIND is not the way to go.
Oct 1 '07 #10
kcddoorman
76 New Member
This is very confusing. It seems like their should be a pre made function for this somewhere. OK. who is M$? is this l33t speak for something I am too noobish to know?

Let me clarify something here I did not realize until now.
This line
Expand|Select|Wrap|Line Numbers
  1. rs.find "[job name] LIKE '" & cstr(InputBox("Please enter a job name to find", "Find"))&"'"
will accept the wildcard character * only in certain conditions. Only if the search string is "Jame*" it will return a job name James. If the search string is "J*es" then I get no matching record. Maybe filtering the recordset is the way to go but I don't believe the salespeople will understand how to do it.
Oct 1 '07 #11
Scott Price
1,384 Recognized Expert Top Contributor
General Information :-)

M$ = Micro$oft (generally a sarcastic reference, eh?)

This link discusses single and double qoutes: Quotes (') and Double-Quotes (") and how to use them

Regards,
Scott
Oct 1 '07 #12
NeoPa
32,556 Recognized Expert Moderator MVP
Expand|Select|Wrap|Line Numbers
  1. rs.find "[job name] LIKE '" & CStr(InputBox("Please enter a job name to find", "Find")) & "&'"
This line of code would assume that the input search string will always have a wildcard after it. So a search for "John" will return not only John but also Johnson or Johnsonville or Johnny Number 5. Right? Or does it not matter.


Ok i just tried this in my code. What it does is append the & character to any string I enter into the textbox. So a search for James is really a search for James&. I'm beginning to think that FIND is not the way to go.
My bad :(
That should have been
Expand|Select|Wrap|Line Numbers
  1. rs.find "[job name] LIKE '" & CStr(InputBox("Please enter a job name to find", "Find")) & "*'"
I was trying to illustrate putting the wildcard (*) character after the string entered.
I haven't tested this with the Find() function but I have with a SQL query where it works as claimed whether within, or at the end of, a comparison string.
Oct 3 '07 #13
NeoPa
32,556 Recognized Expert Moderator MVP
...
Maybe filtering the recordset is the way to go but I don't believe the salespeople will understand how to do it.
Perhaps it would be better to code the filtering in for them. I never rely on operators to manage even walking and talking competently (well talking maybe ;D)
Oct 3 '07 #14
Scott Price
1,384 Recognized Expert Top Contributor
Perhaps it would be better to code the filtering in for them. I never rely on operators to manage even walking and talking competently (well talking maybe ;D)
How about breathing? :-) LOL

Regards,
Scott
Oct 3 '07 #15
NeoPa
32,556 Recognized Expert Moderator MVP
That reminds me of how often my Yoga teacher has to remind the class to continue to breathe normally in the position :D
Pants all around at that point usually.
Oct 3 '07 #16
kcddoorman
76 New Member
Speaking of stretching out; I've been sitting at this computer for hours. I'm starting to feel like quazi modo.
Oct 4 '07 #17
NeoPa
32,556 Recognized Expert Moderator MVP
Go stretch out.
Whatever the drive - always give yourself a physical break at frequent intervals (a couple of hours at most). It will help your brain work better as well as keep you physically healthier :)
Oct 4 '07 #18

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

Similar topics

5
by: Jason | last post by:
Hello. I am trying to learn how operator overloading works so I wrote a simple class to help me practice. I understand the basic opertoar overload like + - / *, but when I try to overload more...
3
by: Markus Dehmann | last post by:
I have a two different value types with which I want to do similar things: store them in the same vector, stack, etc. Also, I want an << operator for each of them. class Value{}; // this would...
2
by: Ed Brown | last post by:
I'm working on a VB.Net application that needs to do quite a bit of string pattern matching, and am having problems using the "LIKE" operator to match the same string twice in the pattern. For...
12
by: ex_ottoyuhr | last post by:
I have a situation more or less as follows, and it's causing me no end of trouble; I'd appreciate anyone's advice on the matter... Given these classes: class BedrockCitizen { ... }; class...
2
by: Piotr Sawuk | last post by:
What is wrong with the following? Why doesn't it compile? template<int f, class me, typename ValType=int> class Fm { protected: ValType v; public: me& operator+=(const me& o)...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

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.