Quotation marks in VBA

Paolo Bernasconi picture Paolo Bernasconi · Nov 28, 2012 · Viewed 83k times · Source

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.

Answer

transistor1 picture transistor1 · Nov 28, 2012

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"