473,385 Members | 1,409 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.

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 60011
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 would be one XML record for each deleted record. ...
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 operator on a varchar field as follows .......
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 name="prefix">profile_joker_</xsl:variable> <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 snapshot type recordset, all sorts of wierd,...
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(, , ) I would like the wildcard after variable 2. ...
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 given a higher precedence over '--'operator? as...
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 (to learn enough ASP/VB.net to port a series of ...
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 &= operator used?
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 feature of the dataview or some other object that I...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.