parsing quotation literals in code (1 Viewer)

vba_php

Forum Troll
Local time
Today, 11:55
Joined
Oct 6, 2019
Messages
2,884
I've been wondering this for years cuz I've only ever used one type of syntax to get the parser to recognize double quotes in a statement or action/function. the method I always use is like so:
Code:
[B][U]SAMPLE SQL in VBA[/U][/B]

"WHERE [field] = " & """" & me.StringControl & """"
but I use this more often than the above example:
Code:
"WHERE [field] = '" & me.control & "'"
I have also seen people make it work apparently using 3 double quote marks in some sort of context? what are all the different options for parsing single and double quote marks in basic?
 

Ranman256

Well-known member
Local time
Today, 12:55
Joined
Apr 9, 2015
Messages
4,339
I find the quadruple quotes confusing and hard to read, so I too, use single quotes.

But not for people names since : O'Malley, and the like will crash it.
so for that I have a global constant: public const Q = """"
then its:
"WHERE [field] = " & Q & me.txtName & Q
 

vba_php

Forum Troll
Local time
Today, 11:55
Joined
Oct 6, 2019
Messages
2,884
I find the quadruple quotes confusing and hard to read, so I too, use single quotes.

But not for people names since : O'Malley, and the like will crash it.
so for that I have a global constant: public const Q = """"
then its:
"WHERE [field] = " & Q & me.txtName & Q
what about the use of single quote marks? aside from using them in the way I show in my example, are the even recognized by access as string encapsulators? every other web language, regardless if it's server side or client side, makes heavy use of single quote for all sorts of operations. I see those used way more than I do double quotes. Access is like the only program I've ever used that only recognizes double quotes as the only possible encapsulator.
 

Cronk

Registered User.
Local time
Tomorrow, 03:55
Joined
Jul 4, 2013
Messages
2,770
Another alternative is chr(34) which handles data with single quote included.


Code:
....."WHERE [field] = " & chr(34) & me.StringControl & chr(34)
 

moke123

AWF VIP
Local time
Today, 12:55
Joined
Jan 11, 2013
Messages
3,852
Or helper functions

Code:
Public Function DLT(strIN As Variant) As String

    DLT = """" & strIN & """"

End Function

"WHERE [field] = " & DLT(me.control)


Code:
Public Function DLD(strIN As Variant) As String

    DLD = "#" & strIN & "#"""

End Function

"WHERE [Datefield] = " & DLD(me.control)
 

Users who are viewing this thread

Top Bottom