Escape sequence

L

Louis

Hi

I am executing a statement in vba to insert a record into a MySQL database.

MySQL sees ' and " as special characters. So i have included a function to
check for these and include an appropriate \ to escape them.

Then it occurred to me that because these characters are in a string - vba
might also recognise them as functional and not textual - so i need to
escape them in vba too. How can i escape them in both? Does vba use the \ as
its escape?

Thanks

Lou
 
R

Ron Weiner

VBA wants you to Double up on the character to escape it. So for example if
you wanted to assign a literal string 37" HD TV to a VBA variable strItem
you'd code it like this. strItem = "37"" HD TV"

Ron W
 
J

John Nurick

Hi Lou,

VBA doesn't use \ as an escape character. But if you want to include "
in a string literal you have to escape it with itself (i.e. double it).
So to put
\"
in a VBA string literal you'd use
"\"""
as against the C-ish
"\\\""
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top