Why Sometimes Chr$34 and others Quotes

  • Thread starter Thread starter Matthew
  • Start date Start date
M

Matthew

Why and when is Chr$34 used to enclose an
object/literal/string as opposed to quotation marks, which
are also used.

Thanks and what would be a good beginners VBA book be in
the experts opinion ?

Again, thanks


Matthew
 
It is done, when you need the results to have quotes in them. As an example, lets assign a
value to a string variable "strVariable".

strVariable = "MyString" will give a value of MyString

strVariable = Chr(34) & "MyString" & Chr(34) will give a value of "MyString"

If you put in 2 consecutive quotation marks, that tells VBA to use them as part of the
string, not as delimiters. So, the above could also be written,

strVariable = """MyString""" will give a value of "MyString"

That's 3 double quotes on each side. The outside ones are the ones you would expect. The
inside ones are 2-double quotes. Using the rule above, that will put a quote in the
output.

The difference between Chr(34) and ""? For the most part, it is personal preference.
Chr(34) is probably easier to read than trying to count all the "", but "" is quicker and
easier to type.
 
chr$(34) is a pain in the butt to type. Wayne's suggestion
is fine but tracking the """""""s is also a pain in the
nether regions. To include quotes try using a mix of "
and '
For example
sqlWhere = "WHERE [Name] like '" &txtName &"'"
It's a lot easier to type and read & who remembers all
those chr numbers
Cheers
Terry
 
Back
Top