473,809 Members | 2,708 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

double quotes in memo field causing parsing issues

35 New Member
Hi,

I am developing a DB that imports a CSV file from a commerce site. The file is a CSV file with double quotes to identify text. In this file, there is a memo field where people occassionally use double quotes. This causes the parsing to corrupt b/c the csv/text file generator is confusing this with the end of the string.

I am aware that using two double quotes is a way to get around this but i am not able to get the csv file to output data this way. is there any other workaround?

thanks

Todd
Jun 19 '09 #1
11 4204
ADezii
8,834 Recognized Expert Expert
@tfurubay
How about Low Level I/O Functions to Convert all Double Quotes ("") to Single Quotes (") immediately before Importing the CSV File as in:
Expand|Select|Wrap|Line Numbers
  1. Dim strLine As String
  2. Const conOriginalFile As String = "C:\Employees.txt"
  3. Const conConvertedFile As String = "C:\Employees_2.txt"
  4.  
  5. If Dir$("C:\Employees_2.txt") <> "" Then Kill conConvertedFile
  6.  
  7. Open conOriginalFile For Input As #1
  8. Open "C:\Employees_2.txt" For Output As #2
  9.  
  10. Do While Not EOF(1)             'Loop until end of file.
  11.     Line Input #1, strLine      'Read line into variable.
  12.     Print #2, Replace(strLine, """""", """")    'Convert "" to " then
  13.                                                 'Output to File
  14. Loop
  15.  
  16. Close #1
  17. Close #2
Jun 20 '09 #2
tfurubay
35 New Member
Hi,

thank you for your kind assistance. where do i build this function? In a module? do i just paste it in and change the file name?

and will the syntax turn

this:
"joe","smith"," I am considered "old" in my family"

to this:
"joe","smith"," I am considered 'old' in my family"?

thanks,

Todd
Jun 22 '09 #3
ADezii
8,834 Recognized Expert Expert
@tfurubay
No, it will convert Double Quotes to Single Quotes, which I thought was the original intention.
Expand|Select|Wrap|Line Numbers
  1. "joe",""smith"","I am considered ""old"" in my family"
will be converted to:
Expand|Select|Wrap|Line Numbers
  1. "joe","smith","I am considered "old" in my family"
Jun 22 '09 #4
tfurubay
35 New Member
that is the desired outcome. do i build this in a module/macro?

thanks so much!
Jun 22 '09 #5
ADezii
8,834 Recognized Expert Expert
@tfurubay
  1. Copy and Paste the following Sub-Routine Procedure to the General Declarations of a Standard Code Module:
    Expand|Select|Wrap|Line Numbers
    1. Public Sub ConvertDoubleQuotes(strOriginalFile As String, strConvertedFile As String)
    2. If Dir$(strConvertedFile) <> "" Then Kill strConvertedFile
    3.  
    4. Open strOriginalFile For Input As #1
    5. Open strConvertedFile For Output As #2
    6.  
    7. Do While Not EOF(1)             'Loop until end of file.
    8.     Line Input #1, strLine      'Read line into variable.
    9.     Print #2, Replace(strLine, """""", """")    'Convert "" to " then
    10.                                                 'Output to File
    11. Loop
    12.  
    13. Close #1
    14. Close #2
    15. End Sub
  2. Call the Sub-Routine passing to it the Name/Path of the File to be converted, and the Name Path of the File after Conversion, as in:
    Expand|Select|Wrap|Line Numbers
    1. Call ConvertDoubleQuotes("C:\Test.txt", "C:\Windows\Test_Converted.txt")
Jun 22 '09 #6
tfurubay
35 New Member
Hi, I think i'm almost there.

i was able to copy #1 into general declarations. I'm stuck on #2. Where do i paste the syntax? do i paste it in general declarations too? I'm trying to build a macro for it and paste the 2nd command.

Call ConvertDoubleQu otes("\\Easerve r\Public\Res DB\ResDownloads \shdownload.csv ", "\\Easerver\Pub lic\Res DB\ResDownloads \shdownloadfixe d.csv")


sorry, i'm a novice!

thank you,

Todd
Jun 24 '09 #7
ADezii
8,834 Recognized Expert Expert
@tfurubay
I'm stuck on #2. Where do i paste the syntax?
The most logical, and easiest, location to place the Code is in the Click() Event of a Command Button.
Jun 24 '09 #8
OldBirdman
675 Contributor
Am I missing something here?

There are quotes(") within quotes("). Some of the quotes delimit the strings in a CSV file, and some are internal and should either be doubled ("") or changed to single('). tfurubay wants to convert these to single quotes(').

10 Do While Not EOF(1)
11 Line Input #1, strLine .
12 Print #2, Replace(strLine , """""", """")
13
14 Loop
Line 12 needs to have a user function, say DoubleToSingle( strLine) instead of Replace(strLine , """""", """") as shown in line 12 above.

Expand|Select|Wrap|Line Numbers
  1. Public Function DoubleToSingle(strInput As String) As String
  2. 'This function assumes that the CSV separating commas 
  3. '        have no blanks next to them
  4. Dim i As Integer
  5. Dim strWk As String
  6. strWk = Trim(strInput)
  7. For i = 2 To Len(strWk) - 1
  8.     If Mid(strWk, i, 1) = """" Then
  9.         If Mid(strWk, i - 1, 1) <> "," And _
  10.                 Mid(strWk, i + 1, 1) <> "," Then
  11.             Mid(strWk, i, 1) = "'"
  12.         End If
  13.     End If
  14. Next i
  15. DoubleToSingle = strWk
  16. End Function 'DoubleToSingle
Jun 24 '09 #9
tfurubay
35 New Member
birdman, i was going to extrapolate and test and substitute because i felt ADezii gave me enough to go on and i would learn in the process. but i thank you profoundly for giving me the exact code that i need.

I'm going to build it this evening. thanks so much for getting me there! And Adezii, thank you for your help and patience!

Todd
Jun 24 '09 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

4
5408
by: Mal | last post by:
I have an ACC 2000 database that has a strange behaviour I have a small table, with just a few fields... My report has very simple grouping and sorting, no code bar a NODATA event. I have a memo field When CAN GROW is set to NO everything works just fine. When CAN GROW is set to YES - watch out.... One record causes BIG
3
5223
by: Helgardh | last post by:
I have a linked table (Access 2003) to an Outlook inbox. The body of the e-mail messages are in a memo field. My problem is that I need to "read" the memo and find data on certain lines. The memo will look something like this: Order: J123451 Placed By: Joe.systems,daily Order: J123452
24
22667
by: deko | last post by:
I'm trying to log error messages and sometimes (no telling when or where) the message contains a string with double quotes. Is there a way get the query to insert the string with the double quotes? Do I need to use code to scrub each string and remove or escape the double quotes before using it in a query? The error I get is this: Error Number 3075: Syntax error (missing operator) in query expression '"credit card billed by...
0
1072
by: robin9876 | last post by:
When openning a table or a query that has a memo field, the memo field is not displayed in the output. However if a form or report is based on the table or query the memo field is displayed. The database is a replication database. What is causing the memo field not to be displayed in a query and how can it be displayed in a query?
16
5891
by: Charles Law | last post by:
I have a string similar to the following: " MyString 40 "Hello world" all " It contains white space that may be spaces or tabs, or a combination, and I want to produce an array with the following elements arr(0) = "MyString" arr(1) = 40 arr(2) = "Hello world"
9
5743
by: RMC | last post by:
Hello, I'm looking for a way to parse/format a memo field within a report. The Access 2000 database (application) has an equipment table that holds a memo field. Within the report, the memo field is printed within the detailed area. The problem is, the apllication is not setup properly, thus the users are entering data within the memo field as: location1 1/1/2005 1/1/2006
10
3061
by: ARC | last post by:
This is mainly a speed question. In this example: I have a QuotesHdr table that has a few memo fields. If these memo fields are used extensively by some users, and if their are a large number of records in QuotesHdr, should I break out the memo fields into a separate table? The thinking here is that, for Quotes selection dropdowns that display all entries in QuotesHdr for selection, I would think that the entire record comes down over...
2
1765
by: Shaia | last post by:
I have a third party tool that creates an Access 2003 database. In one table, there is a memo field that stores HTML chunks. These chunks represent "content" from a web page. If my content ,stored in the memo field, has a single quote character, the character is being removed when I look at the memo field. For example, if I put grapefruit's into the memo field, I get grapefruits out. If can't, I get cant. What is going on here? ...
1
2498
thewesties
by: thewesties | last post by:
Could somebody please help me before I dump a gallon of water on my pc! I am very happy to have come across this site on the internet. TheScripts has helped me through so many issues to this point. I have now spent the last 2 days scouring the net for a resolution to my problem. I have a DB with MANY tables, but a transfer of 1 memo field between 2 in particular (tbl_Proposal to tbl_Job) is where my problem is. Nothing is working. The...
0
9601
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10376
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10379
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7660
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6881
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4332
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3861
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3014
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.