Quotes, apostrophes, etc.

J

JMorrell

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
 
D

Douglas J. Steele

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, " ' ", " ' ' ")
 
J

JMorrell

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
 
Top