In my current VBA code, I have a query in which I am using Chr(34)
to put quotation marks between some of my variables.
I was wondering what alternatives exist to this. This is a simple question, i know, but I haven't had any success with repeating quotation marks like this
"
& variable string here &"
My code is messy for one and not understandable for people who are not familiar with VBA:
comboService = Chr(34) & Me.Combo8.Value & Chr(34)
Also, this hasn't worked:
comboService = """" & Me.Combo8.Value & """"
Can you perhaps tell me why?
Thanks in advance.
The message is displayed without double quotes and is treated as a number. If you want to display string with double quotes, you just have to add additional quotes. If you run this code, Excel will display a text with double-quotes. If you want to add double double-quotes, you have to use 5 double-quotes for each side.
When you enter a single quotation mark, you must enter a second – VBA wants to see a pair of them. If you omit the quotation marks, VBA will interpret Harkins as a variable and then return an error when it doesn't find it (assuming of course that you haven't actually declared a variable named Harkins.)
Use "CHAR(34)" within formulas where you need to output quotation marks. For example, to add quotes around the text in cell A1, you would type "=CHAR(34)&A1&CHAR(34)" in an empty cell.
This:
comboService = """ & Me.Combo8.Value & """
is what you posted, but you need to add an extra quotation mark in order to add a literal quotation mark:
comboService = """" & Me.Combo8.Value & """"
Double-quotes within a string are what you are looking for.
aVar = "This: "" is a literal quotation mark"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With