Microsoft Access
--
Questions
--
Followers
Top Experts
I've tried 'Like *&*' and other variations without success.
Zero AI Policy
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
mx
SELECT Table1.*
FROM Table1
WHERE (((InStr(1,[FIELD1],Chr(38
mx






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
Sorry MX...didnt see you answered before I posted.
.... Hmmm ....
I notice that in your post, you do NOT have quotes around your string .... the follow works just fine:
SELECT * FROM SomeTable WHERE SomeTextField Like "*&*"
SELECT * FROM SomeTable WHERE SomeTextField Like "*&*"

Get a FREE t-shirt when you ask your first question.
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
So in SQL Server syntax (or ADO):
SELECT * FROM SomeTable WHERE SomeTextField Like '%&%'
The safest and most reliable way to make comparisons when special characters are used with InStr() - which ignores them.
mx






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
>>Â The safest and most reliable way to make comparisons when special characters are used with InStr() <<
Ok .... well .... what makes the ampersand a special character? ... The &Â is not a delimitor, nor is it a wild card character, or special delimiter ... the ampersand is just an operator character, so ... its no different than a plus, or minus is it? ... so ... no need to use InStr()
mx

Get a FREE t-shirt when you ask your first question.
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
It's not ... that's kind of my point. Â Many times you will do this:
Like "abc" &Â "*"
         ^^
It this case of this Q ... we are trying to find a &Â in some string. Â InStr() makes this simple and avoids a load of quotes, double quotes or whatever.
mx
Yes I would ...
mx






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
Like "abc" &Â "*" Â <<
Yes that is true ... but how does your expression make the ampersand a "special" character? ... The concatenation of the the two values you have shown simply creates a text pattern to be searched for. Â Your given expression will find all the records that start with "abc" ... if the expression is modified to be like this:
Like "abc&" &Â "*"
Access will find all records that start with "abc&" ... and if the expression is modified to be like this:
Like "abc+" &Â "*"
{Note the + is a concatenator too} Access will find all the records that start with "abc+".
.....
So ... following your logic with the concept that operators should be searched for with InStr(), then you would use InStr() when searching for the patterns "And", "Or", and "Like" too? ... Using InStr() for those operators (as well as the ampersand), although valid, is a detriment to efficiency of the execution of the SQL statement (possibly neglibible, but still a reducer of efficiency), due to the needless call to VBA's InStr().
...
Out of curiousity, can you show me where an operator (other than those that double as wild cards, like the asterick) can cause an issue with the Like operator pattern comparisons? {Note: I said operator, NOT wild card characters or text delimitors :) }
The characters that I would utilize the InStr() for are the ones that are used for pattern expressions, wild cards, or text delimitors {parenthesis used to delimit the character, not to indicate a cadidate for InStr()}:
(?) or (_) Â means any single character.
(*) or (%) Â means zero or more characters in the spot its used.
(#) Â means any single digit (09).
([)charlist(]) Â means any char in the char list within the square brackets (The pair is killer here).
(') or (") Â delimits text, so the SQL interpreter maybe looking for its mate. Â Using "'" (double, single, double) or '"' (single, double, single) is fine ... but trying to use a single in a string that is delimited by singles is no good, just as a double in a string delimited by doubles. Â When a text delimitor is encapsulated by the same delimitor, you can repeat the delimitor being sought. Â For example: Like "ab""" &Â "*" will return all records that start with (ab"). Â Another method is to encapsulate the special character in square brackets ... Like "ab[*]*" will find all records that begin with ab<asterik>.
For more info on searching using the Like operator:
Like Operator (Jet SQL)
http://office.microsoft.com/en-us/access/HP010322531033.aspx
Using Wildcard Characters in String Comparisons
http://office.microsoft.com/en-us/access/HP010322841033.aspx
There are other links that can be followed on those pages ... but ... ulitmately, there is NO NEED for the InStr(), nor is there an increase in safety or reliability in using InStr(), when trying to match a pattern containing the ampersand. Â Again, I ask you to show me a situation where the ampersand causes an issue (ie: is mistaken for an operator instead of part of a string pattern being searched for), I am certainly willing to eat a piece of humble pie if one can be presented.
---------
Please note, my mode of conversation during this post/thread is not intended to sound less than cordial or respectful .... I truly enjoy conversations of this nature and look at these types of discussions as opportunities to learn and/or teach, so ... just wanted to say this so you know that if my tone was being read as "a little on the offensive", please know that I am just talking .... not trying to toss attitude! ... :) .... {sometimes the written word can be so misunderstood with respect to tone}
Microsoft Access
--
Questions
--
Followers
Top Experts
Microsoft Access is a rapid application development (RAD) relational database tool. Access can be used for both desktop and web-based applications, and uses VBA (Visual Basic for Applications) as its coding language.