single quote error

abenitez77

Board Regular
Joined
Dec 30, 2004
Messages
149
I am trying to update a SQL table with the string from excel using vba. strBrokerCategory (sixth line) has a value of "Cat 29 OTC / 2930 Women's Health". The single quote is causing issues for me. How can I fix this ? I tried a Replace(strBrokerCategory, "'", "''") but it does not help. Any help would be appreciated.

tSQL = tSQL & "Values('" & strLCLDeal & "','" & strVendorsDeal & "','" & strDateCreated & "','" & strDealDate & "','" & strDealType & "','" & strActivityType & "','" & _
strDeliveryMethod & "','" & strBillType & "','" & strCatNum & "','" & strPCSNum & "','" & strMCH1 & "','" & strMch1Desc & "','" & strWeek & "','" & _
strYear & "','" & strDealDur & "','" & strPreShipEffDate & "','" & strDealEffDate & "','" & _
strManVendorName & "','" & strManVendorNum & "','" & strManSAPVendNum & "','" & strManAddress & "','" & strManCity & "','" & strManProvince & "','" & strManPostal & _
"','" & strManPhone & "','" & strManRepName & "','" & strManCategory & "','" & strBrokerName & "','" & strBrokerStreet & "','" & strBrokerCity & "','" & _
strBrokerProvince & "','" & strBrokerPostal & "','" & strBrokerPhone & "','" & strBrokerRepName & "','" & Replace(strBrokerCategory, "'", "''") & "','" & strBanner & "','" & _
strBannerCode & "','" & strBanner2 & "','" & strBannerCode2 & "','" & strBanner3 & "','" & strBannerCode3 & "','" & strBanner4 & "','" & strBannerCode4 & _
"','" & strBanner5 & "','" & strBannerCode5 & "','" & strBanner6 & "','" & strBannerCode6 & "','" & strBanner7 & "','" & strBannerCode7 & "','" & _
strBanner8 & "','" & strBannerCode8 & "','" & strBanner9 & "','" & strBannerCode9 & "','" & strBanner10 & "','" & strBannerCode10 & _
"','" & xSheetName & "','" & xFilePath & "','" & xFileName & "')"

Set rs = Connection2.Execute(tSQL)
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
First, I am far from a pro at this. It looks correct to me. So I googled it. I found that your variable is not allowed to have an apostrophe in it for this syntax. Something to look into on your end.
 
Upvote 0
Try replacing Chr(146) as well. But what is your replacement string? A double-quote?
 
Upvote 0
found my issue ... I was using .Value when I should have used .Text to get the data. The replacement string is a single quote.
 
Upvote 0

Similar threads

Forum statistics

Threads
1,223,992
Messages
6,175,829
Members
452,673
Latest member
LaMiaAvy

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top