Quotes, apostrophes, etc.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

The following string

' update table Request
strSQL = "INSERT INTO requests ( [PubID], [EmployeeID], [Location] ) " & _
"values (" & PubID & " , " & EmpID & " , ' " & Loc & " ' );"

fails to recognize the contraction - can’t - because of the apostrophe in
the Location value. Loc is a string variable.

What is the syntax to allow quotes and apostrophes in the & Loc & variable?

tia
 
strSQL = "INSERT INTO requests ( [PubID], [EmployeeID], [Location] ) " &
_
"values (" & PubID & " , " & EmpID & " , " & Chr$(34) & Loc &
Chr$(34) ");"

or

strSQL = "INSERT INTO requests ( [PubID], [EmployeeID], [Location] ) " &
_
"values (" & PubID & " , " & EmpID & " , '" & Replace(Loc,
"'", "''") & "' );"

where that's Replace(Loc, " ' ", " ' ' ")
 
that's just the ticket!

thanks again for all your help.

JMorrell


Douglas J. Steele said:
strSQL = "INSERT INTO requests ( [PubID], [EmployeeID], [Location] ) " &
_
"values (" & PubID & " , " & EmpID & " , " & Chr$(34) & Loc &
Chr$(34) ");"

or

strSQL = "INSERT INTO requests ( [PubID], [EmployeeID], [Location] ) " &
_
"values (" & PubID & " , " & EmpID & " , '" & Replace(Loc,
"'", "''") & "' );"

where that's Replace(Loc, " ' ", " ' ' ")

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



JMorrell said:
The following string

' update table Request
strSQL = "INSERT INTO requests ( [PubID], [EmployeeID], [Location] ) " & _
"values (" & PubID & " , " & EmpID & " , ' " & Loc & " );"

fails to recognize the contraction - can't - because of the apostrophe in
the Location value. Loc is a string variable.

What is the syntax to allow quotes and apostrophes in the & Loc & variable?

tia
 

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

Back
Top