469,326 Members | 1,534 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,326 developers. It's quick & easy.

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 57412
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Ravi | last post: by
21 posts views Thread by siliconwafer | last post: by
8 posts views Thread by John Pass | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by listenups61195 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.