My requirement is to remove the special characters especially double quotes from the adodb recordset while exporting to CSV in VB6 using the below code.
if any double quotes is present the value after double quotes is moved to next column.
Specifically, the double quotes are present in rsData.Fields(K).Value not in rsData.Fields(K).Name. I'm not sure how to remove the double quotes in rsData.Fields(K).Value.
Any help to fix this issue will be greatly appreciated. Thanks in advance.
'Converting the recordset
Public Function RecordsetToCSV(rsData As ADODB.Recordset, Optional ShowColumnNames As Boolean = True, Optional NULLStr As String = "") As String
Dim K As Long, RetStr As String
If ShowColumnNames Then
For K = 0 To rsData.Fields.Count - 1
RetStr = RetStr & ",""" & rsData.Fields(K).Name & """"
Next K
RetStr = Mid(RetStr, 2) & vbNewLine
End If
RetStr = RetStr & """" & rsData.GetString(adClipString, -1, """,""", """" & vbNewLine & """", NULLStr)
RetStr = Left(RetStr, Len(RetStr) - 3)
RecordsetToCSV = RetStr
End Function
'Creating CSV file
Dim CSVData As String
CSVData = RecordsetToCSV(rsData, True)
Open "C:\test.csv" For Binary Access Write As #1
Put #1, , CSVData
Close #1
reference : https://www.vbforums.com/showthread.php?481705-VB6-Save-Recordset-to-CSV-format