Quote in a string

Quote in a string

Anonymous
Not applicable
530 Views
6 Replies
Message 1 of 7

Quote in a string

Anonymous
Not applicable
Is there a way to express the string 3" in vba other than "3" & chr(34)?
"3"" obviously doesn't work. It is for a text box validation that passes the
contents to an SQL query. When the user enters a double quote I want to
translate it into something SQL likes.

Dale
0 Likes
531 Views
6 Replies
Replies (6)
Message 2 of 7

Anonymous
Not applicable
Sample:
ls_Desc = "*" & as_D & "*"
SQL String portion = tblCustomPricingQuotes.Description LIKE " & Chr(34) &
ls_Desc & Chr(34)

Now as_D is the string that gets passed from the text box whixh will allow
the recordset to include all records where field "Description" contains the
text passed via as_D.

If user enters X then the matxh string is "*X*". As soon as the user enters
a double quote I get an SQL query error when it tries to pass the query
string.

Any suggestions?

Dale
0 Likes
Message 3 of 7

Anonymous
Not applicable
If _D held consistent data, you could just build your sql string
appropriately. But since its variable, you'll have to test whether or not it
contains a double quote before you build your sql string. Search _D for a
double qoute and replace it with two double qoutes.

--
Ed
--

"Dale Levesque" wrote in message
news:F045C74420F8D15F10553B59033EE94C@in.WebX.maYIadrTaRb...
> Sample:
> ls_Desc = "*" & as_D & "*"
> SQL String portion = tblCustomPricingQuotes.Description LIKE " & Chr(34)
&
> ls_Desc & Chr(34)
>
> Now as_D is the string that gets passed from the text box whixh will allow
> the recordset to include all records where field "Description" contains
the
> text passed via as_D.
>
> If user enters X then the matxh string is "*X*". As soon as the user
enters
> a double quote I get an SQL query error when it tries to pass the query
> string.
>
> Any suggestions?
>
> Dale
>
>
0 Likes
Message 4 of 7

Anonymous
Not applicable
Works great!

"Ed Jobe" wrote in message
news:97B0EF0F405958AD8149907FB958B9DA@in.WebX.maYIadrTaRb...
> If _D held consistent data, you could just build your sql string
> appropriately. But since its variable, you'll have to test whether or not
it
> contains a double quote before you build your sql string. Search _D for a
> double qoute and replace it with two double qoutes.
>
> --
> Ed
> --
>
> "Dale Levesque" wrote in message
> news:F045C74420F8D15F10553B59033EE94C@in.WebX.maYIadrTaRb...
> > Sample:
> > ls_Desc = "*" & as_D & "*"
> > SQL String portion = tblCustomPricingQuotes.Description LIKE " &
Chr(34)
> &
> > ls_Desc & Chr(34)
> >
> > Now as_D is the string that gets passed from the text box whixh will
allow
> > the recordset to include all records where field "Description" contains
> the
> > text passed via as_D.
> >
> > If user enters X then the matxh string is "*X*". As soon as the user
> enters
> > a double quote I get an SQL query error when it tries to pass the query
> > string.
> >
> > Any suggestions?
> >
> > Dale
> >
> >
>
>
0 Likes
Message 5 of 7

Anonymous
Not applicable
"3"" won't work, of course. the first " and the last " are bracket for a
string value. To present a " value in VB's string, you duoble the ", that
is:

Dim myString As String

myString="3""" 'the string's value is 3"
myString="ABCD""EFG" 'the string's value is ABCD"EFG

"Dale Levesque" wrote in message
news:4F74F895861B84222E5DB47BB8F8C9E6@in.WebX.maYIadrTaRb...
> Is there a way to express the string 3" in vba other than "3" & chr(34)?
> "3"" obviously doesn't work. It is for a text box validation that passes
the
> contents to an SQL query. When the user enters a double quote I want to
> translate it into something SQL likes.
>
> Dale
>
>
0 Likes
Message 6 of 7

Anonymous
Not applicable
Not sure what method you used to implement Ed's suggestion, but if you're using VBA 6.x there is a Replace function that'll do the work for you.



Regards



Wayne Ivory

IT Analyst Programmer

Wespine Industries Pty Ltd
0 Likes
Message 7 of 7

Anonymous
Not applicable
Thanks, I have one.


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
Not
sure what method you used to implement Ed's suggestion, but if you're using
VBA 6.x there is a Replace function that'll do the work for you.

  
Regards
  
Wayne Ivory
IT Analyst
Programmer
Wespine Industries Pty Ltd
0 Likes