Resolved--String manipulation in VBA
Hi ppl,
I have following situation. I have a form containing First name text box and the last name text box. When I press confirm button on this form, it concatenated First name and the last name to give me full name as a parameter that I am passing to the next form. However, problem comes if a user has last name like "O'Neil" or "O'Hair" or "O'Dell" the compiler does not understandd that apostrohy sign and gives me a runtime error.
Does anyone know how do I access such string which contains characters such as " " " , " ' ", "`"
Thanks in advance,
Vikram Bartakke
Re: String manipulation in VBA
Usually we see this issue when dealing with a query to a db. To get around that we would just
double up on the single quote using the replace function.
VB Code:
strString = txtFirst & "," & txtLast
strString = Replace(strString, "'", "''")'
Re: String manipulation in VBA
Quote:
Originally Posted by vikram.bartakke
Hi ppl,
I have following situation. I have a form containing First name text box and the last name text box. When I press confirm button on this form, it concatenated First name and the last name to give me full name as a parameter that I am passing to the next form. However, problem comes if a user has last name like "O'Neil" or "O'Hair" or "O'Dell" the compiler does not understandd that apostrohy sign and gives me a runtime error.
Does anyone know how do I access such string which contains characters such as " " " , " ' ", "`"
Thanks in advance,
Vikram Bartakke
To place (") in a String in VB, use (""). ie..
VB Code:
strText = "This ""String"" Contains double-quotes"
Re: String manipulation in VBA
Hi ppl,
Thank you very much for your help. It worked fine. I knew about this problem but the time when i actually implemented this application i was ignorant :)
Ignorance is not bliss always :))
Re: String manipulation in VBA
We were glad to have helped :thumb:
Ps, dont forget to Resolve your thread ;)