Hi Kyle,
I don't know if you ever got anywhere with this, but there's a couple of
possible workarounds I can think of. First off, I'm assuming you're
connecting to SQL Server here...I don't think ADP's can connect to anything
else, but haven't played around all that much, so I'm not positive.
Anyway, first try putting the @ in square brackets...or put a back-slash or
forward-slash before it, or maybe a single quotation? (whatever the default
escape character is for SQL Server)
If you don't get anywhere with that, try replacing your "@" with
CHAR(64)...outside the quotes, obviously. So your string would look like
this:
select * from vwLBFlagSearchResults where LineID in (select distinct
LineID from vwSearch where RespondentEmail='email6' + CHAR(64) + 'x.com')
It sort of defies the point of ADO, since you're now using SQL
Server-specific commands, but if nothing else works, that'll almost
certainly work around your problem.
For myself, I've set up a function that auto-formats a string for the
server, thus putting all the necessary logic in one place, should the
requirements ever change (new version of SQL Server, port to some other
server, whatever). So my VB code would look something like this...
Public Function ServerString(ByVal strIn As String) As String
'This function makes a broad array of assumptions about the string and
does not try to handle unusual situations
'like pre-existing SQL code in the string, other unusual characters,
etc., which might create
'problems under some circumstances. It's just here to give you an idea
of what the function would look like
'and some of the things it would typically address.
'This is actually a really short function, it's all my comments that
make it long.
![Stick Out Tongue :P :P](/styles/default/custom/smilies/tongue.gif)
Feel free to remove them,
're-distribute this function, whatever...I don't really care much.
'Always do single quotes first, cuz otherwise you might replace single
quotes from lines below.
strIn = Replace(strIn, "'","''")
'Replace @ sign.
strIn = Replace(strIn, "@", "' + CHAR(64) + '")
'Replace Carriage Return/Linefeed combo.
strIn = Replace(strIn, vbCrLf, "' + CHAR(13) + CHAR(10) + '")
'Surround the final string by single quotes.
'I find this convenient to do in a function like this, since it provides
you with server-specific
'string formatting that's completely ready-to-go when it returns from
the function
'(Jet, for example would use double-quotes instead of single).
strIn = "'" & strIn & "'"
'From here, if you wish, you can optimize things like any unecessary
empty strings introduced into the final result by an input
'string such as @ <CR/LF> @, which would produce the following using the
above code:
' '' + CHAR(64) + '' + CHAR(13) + CHAR(10) + '' + CHAR(64) + ''
strIn = Replace(strIn, "+ '' +", "+")
If Left$(strIn, 5) = "'' + " Then strIn = Mid$(strIn, 6)
If Right$(strIn, 5) = " + ''" Then strIn = Left$(strIn, Len(strIn) - 5)
'And finally pass back your modified string.
ServerString = strIn
End Function
sign------------------------------------------------------------------------
------------------------------------^