Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Syntax for @ and & in VBA criteria string

Status
Not open for further replies.

dbram

Technical User
Nov 20, 2002
12
US
~
Syntax for @ and & in VBA criteria string

In an Access97 query, the following criteria works perfectly on a text field containing email addresses:
Like "*" & "@aol.com"

However, I cannot seem to get the syntax correct to use that criteria in my VBA string variable.
Dim strLike as String
strLike = "Like "*" & "@aol.com""
' I've tried all sorts of combinations of syntax with "" and &&.

The Microsoft Access compile errors include:
Expected: end of statement
Invalid character 'indicating the @

When I don't get a compile error, I get a runtime error:
3075 : Syntax error (missing operator) in query expression '(((tablename.fieldname) Like * & aol.com))'

I've tried different quotation syntax, still get the errors. A double ampersand is supposed to allow one ampersand to be used in a string, but that gives the errors as well. I am baffled that the @ is an invalid character.

I have tried searching Access help, Microsoft Knowledgebase, Tek-Tips forums without seeing the resolution. Thanks in advance for any help at the end of this frustrating week.

~ db ~


~*~*~*~*~*~
Show me the way home.
~*~*~*~*~*~
 
Hi dbram,

Why the concatenation? You can just use ..

Like "*@aol.com"

which, as a VBA string literal, would be

"Like ""*@aol.com"""

Enjoy,
Tony
 
or....

strLike = "Like *" & "@aol.com"



Sometimes you need single quotes

strLike = "'Like *" & "@aol.com'"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top