472,350 Members | 1,617 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

using LIKE operator with wildcard & variable in VBA

I'm guessing this has been explained before, but I can not seem to
phrase the search correctly.
I am trying to use a string (strString) in a VBA select query. I want
to include the * wildcard in front of and behind the string.
How do I make this work?

Dec 24 '06 #1
5 59367
Zammy wrote:
I'm guessing this has been explained before, but I can not seem to
phrase the search correctly.
I am trying to use a string (strString) in a VBA select query. I want
to include the * wildcard in front of and behind the string.
How do I make this work?
Dim sql as String

sql="SELECT * FROM TableName " & _
"WHERE FieldName Like '*" & strString & "*'"

--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com
Dec 24 '06 #2

I'm sorry, my string is ssWord.
strTableName= tblSongs.

The code I entered was:

strSQL = "SELECT ArtistName,TrackName " & _
"FROM " & strTableName & _
" WHERE ArtistName = Like '*" & ssWord & "*' OR TrackName =
Like '*" & ssWord & "*';"

This is giving me a runtimeerror 3075

Dec 24 '06 #3
Zammy wrote:
I'm sorry, my string is ssWord.
strTableName= tblSongs.

The code I entered was:

strSQL = "SELECT ArtistName,TrackName " & _
"FROM " & strTableName & _
" WHERE ArtistName = Like '*" & ssWord & "*' OR TrackName =
Like '*" & ssWord & "*';"

This is giving me a runtimeerror 3075
You have both "=" and "Like" in the second criteria. Remove the "=" and you
should be fine.

--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com
Dec 24 '06 #4

Thank you. I was beating my head against the wall.

Dec 24 '06 #5
Zammy wrote:
Thank you. I was beating my head against the wall.
Always a good idea when building up complex strings to send the result to the
debug window so you can examine the result. Stuff like that would have been
very easy to spot.

Debug.Print VariableName

--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com
Dec 24 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: DaveS | last post by:
Hello, I'm using Oracle 9.2 and would like to automatically save a copy of each deleted record in XML format to another database table. There...
12
by: Niall Porter | last post by:
Right this has to be a Micro$oft mess-up surely...? I'm running SQL 2k standard with SP3. I have a table which I'm trying to query using a LIKE...
1
by: Ravi | last post by:
My XML looks like: <role type="Joker"> <Profile id="13">ABC_Organization</Profile> </role> My XSL looks like: <xsl:variable...
10
by: Steve Jorgensen | last post by:
Microsoft acknowledges a bug with this, but the bug is worse than they say. It turns out that if you use the Like operator without a wildcard on a...
1
by: Law.Win | last post by:
I have an IIF statement in the criteria of a query. I would like to know how to use a wildcard with the varaibles inside it. For example IIF(, ,...
21
by: siliconwafer | last post by:
Hi, In case of following expression: c = a && --b; if a is 0,b is not evaluated and c directly becomes 0. Does this mean that && operator is...
4
by: Friday | last post by:
Being an Old L.A.M.P guy, I beg you to please excuse my ignorance of dot.net (and all things Windows, for that matter). As part of an experiment...
8
by: John Pass | last post by:
When displaying output in a MessageBox, using a variable Output as string, the &= operator is used instead of the = operator. In which cases is the...
4
by: =?Utf-8?B?UmljaA==?= | last post by:
Is it possible to use a wildcard like feature with Dataview.Find? Actually, I tried that but did not get any rows. Is there some wildcard like...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....

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.