By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,455 Members | 1,979 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,455 IT Pros & Developers. It's quick & easy.

using LIKE operator with wildcard & variable in VBA

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a

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

P: n/a
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

P: n/a

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

Dec 24 '06 #5

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.