Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Apostrophes with INSERT statements

Status
Not open for further replies.

Tim2525

Technical User
Feb 7, 2005
51
0
0
US
Hi All,

I'm doing an INSERT of data from a temp table to another table. My issue is one of my fields has data with an apostrophe in it and it's messing up my insert. Is there a way of working around this where the data is inserted into the field including the apostrophe. Below is my insert statement.

Example of data: Dr's A and B

Code:
strSQL = "INSERT INTO tblPhysicians (drLicense, firstName, middleName, lastName, suffix, " & _
"specialty, subSpecialty, practiceName, address, address2, city, state, " & _
"zipCode, phone, extension, fax, alternateAddress, alternateAddress2, " & _
"alternateCity, alternateState, alternateZipCode, alternatePhone, alternateExtension, alternateFax) " & _
"VALUES ('" & Trim(strLicNbr) & "', '" & Trim(strFirst) & "', " & _
"'" & Trim(strMiddle) & "', '" & Trim(strLast) & "', '" & Trim(strSuffix) & "', " & _
"'" & Trim(strSpecialty) & "', '" & Trim(strSubSpecialty) & "', '" & Trim(strGroup) & "', " & _
"'" & Trim(strAddress) & "', '" & Trim(strAddress2) & "', '" & Trim(strCity) & "', " & _
"'" & Trim(strState) & "', '" & Trim(strZip) & "', '" & Trim(strPhone) & "', " & _
"'" & Trim(strExt) & "', '" & Trim(strFax) & "', '" & Trim(strAltAddress) & "', " & _
"'" & Trim(strAltAddress2) & "', '" & Trim(strAltCity) & "', '" & Trim(strAltState) & "', " & _
"'" & Trim(strAltZip) & "', '" & Trim(strAltPhone) & "', '" & Trim(strAltExt) & "', " & _
"'" & Trim(strAltFax) & "');"

TIA,

Tim
 
For each of the criteria which can contain apostrophes, try something like this

[tt]...'" & replace(Trim(strAltFax), "'", "''") & "');"[/tt]

which will double up the number of apostrophes in the string, which will make the db accept it as one - strange but ...

Roy-Vidar
 
Thanks RoyVidar. Will give it a try.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top