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. - 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? - 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. - <SCRIPT language=vbscript event=onclick for=cmdCustomerSearch>
-
<!--
-
' Clone the recordset.
-
-
Dim rs
-
Set rs = MSODSC.DataPages(0).Recordset.Clone
-
On error resume next
-
-
'rs.find "[CUSTOMER NAME]=" & cStr(InputBox("Please enter customer to find", "Find"))&""
-
rs.find "[Customer NAME] = '" & CStr(InputBox("Please enter customer to find", "Find")) & "'"
-
' error handling
-
-
If (err.number <> 0) Then
-
Msgbox "Error: " & err.number & " " & err.description,,"Invalid Search"
-
Exit Sub
-
End If
-
' Check search results for success.
-
If (rs.bof) or (rs.eof) Then
-
Msgbox "No Product found",,"Search Done"
-
Exit Sub
-
End If
-
MSODSC.DataPages(0).Recordset.Bookmark = rs.Bookmark
-
-->
-
</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
17 4215 FishVal 2,653
Recognized Expert Specialist
Hi, James.
Try to enter '%' wildcard instead of '*'.
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: - 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.
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: - 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?
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.
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. ;)
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. - rs.find "[job name] LIKE '" & CStr(InputBox("Please enter a job name to find", "Find")) & "'"
should be - 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.
NeoPa 32,556
Recognized Expert Moderator MVP 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.
- 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.
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 - 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.
NeoPa 32,556
Recognized Expert Moderator MVP - 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 - 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.
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)
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
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.
Speaking of stretching out; I've been sitting at this computer for hours. I'm starting to feel like quazi modo.
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 :)
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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)...
|
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...
|
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,...
|
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: 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...
|
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...
|
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,...
|
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...
|
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...
|
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...
| |