Help, how do I import a CSV file when Negatives are in Parenthesis

I am attempting to import a Comma Separated Value (CSV) file into an MS 
Access 2007 mdb table.  The table consists of text and numeric (defined as 
Double) fields.

Unfortunately, negative amounts are NOT enclosed by double quotes in the CSV 
file, instead the are enclosed with parenthesis signs.

Example:

"10,485.16","24",(42),"16.35",(835.33)

Currently, when I import the CSV file, the negative amounts are NOT imported.

I need assistance with how to import these negative amounts.

Thanks in advance.
0
Utf
1/5/2010 7:20:01 PM
access.modulesdaovba 1670 articles. 0 followers. Follow

3 Replies
2117 Views

Similar Articles

[PageSpeed] 40

"ND Pard" <NDPard@discussions.microsoft.com> wrote in message 
news:1EB07877-22EC-4366-A2CF-4D58FA29403F@microsoft.com...
>I am attempting to import a Comma Separated Value (CSV) file into an MS
> Access 2007 mdb table.  The table consists of text and numeric (defined as
> Double) fields.
>
> Unfortunately, negative amounts are NOT enclosed by double quotes in the 
> CSV
> file, instead the are enclosed with parenthesis signs.
>
> Example:
>
> "10,485.16","24",(42),"16.35",(835.33)
>
> Currently, when I import the CSV file, the negative amounts are NOT 
> imported.
>
> I need assistance with how to import these negative amounts.
>
> Thanks in advance.

Here's one way:

First load the entire file into a string
Then replace all instances of left paranthesis with minus sign
Then replace all instances of right paranthesis with zero-length string
Save the string as a new file (or overwrite the original) and import that.

Dim f As Integer, buf As String

Open "c:\temp\myFileName.csv" For Binary Access Read As f
buf = Space$(LOF(f))
Get #f, , buf
Close f
buf = Replace(buf, "(", "-")
buf = Replace(buf, ")", "")
Open "c:\temp\myFileName1.csv" For Binary Access Write As f
Put #f, , buf
Close f


0
Stuart
1/5/2010 8:11:40 PM
Thanks Stuart.  Unfortunately I was unable to run your subprocedure in 
Access.  I am not sure why not; however, your solution allowed me to write 
the following procedure using the File System Object (or FSO) that did work.

Sub Replace_Negative_TextStream()
'This subprocedure reads the selected CVS file one line at a time.
'It then replaces any  ,(  with  ,"-  in the line read
'and replaces any  ),  with  ",   in the line read.
'Thus, a negative number that looked like:  ,(42.84),  will not appear as  
,"-42.84",
'Finally, it writes the revised line to the text file: 
BUS-BillHistory_NegRevised.csv

'set a reference to: Microsoft Scripting Runtime via Tools | References
    Dim fso As FileSystemObject
    Dim tsIN As TextStream
    Dim tsOUT As TextStream
    Dim strLineRead As String
    Dim strFileToRead As String
    Dim FLD As Object
    Const ForReading = 1, ForWriting = 2, ForAppending = 8
    
    strFileToRead = "C:\temp\myFileName1.csv"
    
    Set fso = New FileSystemObject
    
    Set FLD = fso.GetFolder("C:\Temp\")
    'Debug.Print FLD.Type
  
    'Re-write the file to a new CVS text file 
    Set tsOUT = FLD.CreateTextFile("myFileName1_NegRevised.csv", True)
    'If the above value is True if the file can be overwritten; 
    'False if it can't be overwritten. 
    'If omitted, existing files are not overwritten.
    
    Set tsIN = fso.OpenTextFile(strFileToRead, ForReading)
    
    While Not tsIN.AtEndOfStream
        strLineRead = tsIN.ReadLine
        strLineRead = Replace(strLineRead, ",(", ",""-")
        strLineRead = Replace(strLineRead, "),", """,")

        With tsOUT
            .Write strLineRead
            .Write Chr(13)
        End With
    Wend
    
    tsOUT.Close

    Set tsIN = Nothing
    Set tsOUT = Nothing
    Set FLD = Nothing
    Set fso = Nothing
    
End Sub
0
Utf
1/6/2010 4:12:01 PM
"ND Pard" <NDPard@discussions.microsoft.com> wrote in message 
news:E5C4638C-9900-494C-8AE1-822F72D07A93@microsoft.com...
> Thanks Stuart.  Unfortunately I was unable to run your subprocedure in
> Access.  I am not sure why not; however, your solution allowed me to write
> the following procedure using the File System Object (or FSO) that did 
> work.
>
> Sub Replace_Negative_TextStream()
> 'This subprocedure reads the selected CVS file one line at a time.
> 'It then replaces any  ,(  with  ,"-  in the line read
> 'and replaces any  ),  with  ",   in the line read.
> 'Thus, a negative number that looked like:  ,(42.84),  will not appear as
> ,"-42.84",
> 'Finally, it writes the revised line to the text file:
> BUS-BillHistory_NegRevised.csv
>
> 'set a reference to: Microsoft Scripting Runtime via Tools | References
>    Dim fso As FileSystemObject
>    Dim tsIN As TextStream
>    Dim tsOUT As TextStream
>    Dim strLineRead As String
>    Dim strFileToRead As String
>    Dim FLD As Object
>    Const ForReading = 1, ForWriting = 2, ForAppending = 8
>
>    strFileToRead = "C:\temp\myFileName1.csv"
>
>    Set fso = New FileSystemObject
>
>    Set FLD = fso.GetFolder("C:\Temp\")
>    'Debug.Print FLD.Type
>
>    'Re-write the file to a new CVS text file
>    Set tsOUT = FLD.CreateTextFile("myFileName1_NegRevised.csv", True)
>    'If the above value is True if the file can be overwritten;
>    'False if it can't be overwritten.
>    'If omitted, existing files are not overwritten.
>
>    Set tsIN = fso.OpenTextFile(strFileToRead, ForReading)
>
>    While Not tsIN.AtEndOfStream
>        strLineRead = tsIN.ReadLine
>        strLineRead = Replace(strLineRead, ",(", ",""-")
>        strLineRead = Replace(strLineRead, "),", """,")
>
>        With tsOUT
>            .Write strLineRead
>            .Write Chr(13)
>        End With
>    Wend
>
>    tsOUT.Close
>
>    Set tsIN = Nothing
>    Set tsOUT = Nothing
>    Set FLD = Nothing
>    Set fso = Nothing
>
> End Sub

Glad you got it working, but I'm curious as to why my code 'didn't work'. 
Did it compile? Did you get an error? If so, on which line?

That's if you remember what happened before writing your version :-)


0
Stuart
1/6/2010 4:32:47 PM
Reply:

Similar Artilces:

Here is fix for Windows file problems
If you have installed a Windows update and started having problems opening, closing, copying files, see: http://www.microsoft.com/communities/newsgroups/list/en-us/default.aspx?dg=microsoft.public.excel.misc&mid=1fe358b1-c8eb-4217-ad2a-4b9fcf741916 A better solution is offered at http://support.microsoft.com/kb/918165 "Problems in Windows Explorer or the Windows shell after you install security update MS06-015". Patricia Shannon wrote: > If you have installed a Windows update and started having problems opening, > closing, copying files, see: > > http://ww...

QuickSell Import Bug
Hi, I am using QuickSell to import new items in HQ and have encountered a problem. Whilst when adding new items the utility functions properly, when editing existing items and using the Recently Changed mechanism to download data to the stores, items which have been edited using QuickSell import do not appear. Has anyone encountered the same situation and perhaps found a workaround? ...

Fax Icon on my File menu and toolbar
I had a Fax Icon on my toolbar and also on the file menu. All of a sudden it is gone and I want it back. Where did it go? Was it a dedicated toolbar? Or was it just icons on a builtin toolbar? If it was a dedicated toolbar, you may get lucky and find it under: Tools|customize|toolbars tab (just not selected) But if it was on a builtin toolbar (along with the file menu), then maybe you reset your toolbar--also under: Tools|customize|toolbars tab selecting a toolbar and hitting the reset button. If that's what happened, I think I might try to find the Fax addin/workbook that added t...

exporting outlook 2000 pst files to a database
I need to export outlook 2000 to a database- attachments and all. Is there a simple way to do this so you can search and retreive messages and attachments in a database form? Thanks Jeff You can export individual folders to access or excel to have them available for searching. I have never tried to export my entire .pst file to access or excel however. --� Milly Staples [MVP - Outlook] Post all replies to the group to keep the discussion intact. After searching google.groups.com and finding no answer Jeff <laacid@yahoo.com> asked: | I need to export outlook 2000 to a database- ...

office 2000 [excel] cannot open previously OK file. Help
When trying to open a Microsoft Excel Work Sheet that I had accessed modified and saved to only yesterday [Office 2000] a window pops up with: "name.xls cannot be accessed. The file may be resd-only, or you may be trying toaccess a read only location. Or, the server the document is stored on may not be responding." Older files stored on the same mediums ;HD, Flash memory or 3.5in. diskette are accessed with no problem. This is on a network drive? ...

Excel and some disappeared sheets
Anybody has the same or similar experiences : - I worked with excel file / closed as usually - new day opened and unfortunatelly some very important sheets disappeared / why ? Don=B4t know - I had about 7-9 sheets just now only 3 ones are there but not so important as another ones - the file has original size / I quickly looked into file by normal text editor only for reading and all relevant data are there, however if I open file by Excel, NO original sheets or data are there. - this file is VERY IMPORTANT for me - why happened ? Don=B4t know since I ask anybody for help Thanks in advan...

Outlook receiving zip files
Why is it when I try to send zipped files to my address; it gets returned as service unavailable? Hello Omar, your Exchange dont allow you to send this! Please speak with your Domain Admin "Omar" <anonymous@discussions.microsoft.com> schrieb im Newsbeitrag news:0754E7DA-31DC-4966-9FC1-C290A8D8222C@microsoft.com... > Why is it when I try to send zipped files to my address; it gets returned as service unavailable? Hi Omar, your Provider don�t supportet this part of file! -- Gestern lief noch alles, ich habe nichts gemacht! Bitte in der Newsgroup antworten, damit jeder d...

unable to read file #7
Does anyone know how to solve this error? This is the second time I have had the same error on the same file. Last time I was able to recover from a saved copy and updated fine. This time whenI opened the copy and updated it, then saved it, I got the same error when I tried to open it again, Now I don't have a good copy. I have downloaded all avaliable updates and tried running "Excel.exe /regserver>ok" This did not help. I also ran defran on the drive. "Randell" wrote > Does anyone know how to solve this error? This is the > second time I have had th...

SBS 2003 moving of users files
I run SBS 2003 and due to the amount of data on the users drive it has become chokers and have installed a new 1tb drive to keep up with demand for space. I need to move all the data to the new drive but unsure of the process. Is there an easy way of doing this? As it needs to be done asap Thanks -- JimmyJames ------------------------------------------------------------------------ JimmyJames's Profile: http://forums.techarena.in/members/255792.htm View this thread: http://forums.techarena.in/small-business-server/1357051.htm http://forums.techarena.in You c...

Importing AOL Email File Cabinet
Is it possible to tranfer a complete AOL Email File Cabinet into outlook? AFAIK, no, but see if anything here will do it: http://www.slipstick.com/config/convmsg.htm - check out Address Magic Plus first, it can convert almost anything. -- Diane Poremsky [MVP - Outlook] Need Help with Common Tasks? http://www.outlook-tips.net/beginner/ Outlook 2007: http://www.slipstick.com/outlook/ol2007/ Outlook Tips by email: dailytips-subscribe-request@lists.outlooktips.net EMO - a weekly newsletter about Outlook and Exchange: EMO-NEWSLETTER-SUBSCRIBE-REQUEST@PEACH.EASE.LSOFT.COM Outlook Tips: http:/...

OL2002 Problem : HELP, SOS, MAYDAY
Hi, I have an IMAP account and OL2002 as client. I have checked for my account ( tools, send/receive settings, define send/receive groups, <my_account>, edit) download item description only. It works only the first time I start OL2002, but it does not work anymore for subsequent automatic/manual send/receive operations. Please could someone really help me ? Thank you in advance, Patrick ...

140 MB file went to 5.08 MB after editting 1 table
Hello All - I need some ACCESS insight...please... Several years ago, I built an access db to track my business scheduling and accounts payable/receivable. So this database is EXTREMELY IMPORTANT TO ME. The file has grown to 140 MB. Today I made a copy of the file and then edited my calendar table. I removed all columns which had 2006 data (72 totals columns) - the table had about 144 columns originally. I then added 72 columns with 2008 headers. These columns are now blank since I have not added any 2008 data yet. Afterwards, I looked around and everything looks good - my 2007 data is the...

a few basic question about resource files
Hi, I have an application that uses resource files to contain the string values for each language. I have created the required resource files in my project, but I don't speak the languages I wish to have resources for. What I would like to do, is somehow allow the end user to edit the resource file themselves so they can set the string values as needed. Is there a way to edit the resource files that ship with my application and get installed ? or Is there a way to have external resource files (not embedded into my application) that can be updated/replaced with o...

Exporting contacts in a csv file
I am a mysterious problem exporting my contacts as csv file. The resulting file has only 58 contacts out of almost 1200 contacts in my outlook. These contacts appear to be the last 58 contacts added. (I say appear because the attribute "createdon" is not exported so I can't be exact. Why is this? cinnamngrl <cinnamngrl@gmail.com> wrote: > I am a mysterious problem exporting my contacts as csv file. The > resulting file has only 58 contacts out of almost 1200 contacts in my > outlook. These contacts appear to be the last 58 contacts added. (I > say appea...

is there a way to program my Excel file to do a loop?
Hi all, If I want B10 to B17 all follow the change of the same number(copy cell), let's say I put it in A1, and C10 follows the change of A2(copy cell), and C11 follows the change of A3(copy cell), and C12 follows the change of A4(copy cell), then I have 4 variables in my calculations: A1, A2, A3, A4. I want to loop each of the variables in a different set, then I hope the whole worksheet will be able to refresh following the change of A1, A2, A3, A4, and then I want to find the very set of A1, A2, A3, A4 that gives the smallest value of D10, how do I program the whole procedure...

Publisher can not save file
I recently started having troubles with my Publisher 2003. Whenever I go to save my files now, using save as or just the save button, it gives me a dialog box that says "Can not save file." It does that twice, then it disappears. I also noticed that when it does this, it leaves the .tmp files in the directory where I tried to save. I can change the name of the files, and sometimes it will save it. Most of the time not though. I have NAV, and I noticed that it was said there was an issue with Publisher and NAV. Is this the same with the 2005 version, and is this anything anyone...

Help With Margin Formula
Hello, I need help with a margin forumla (calculated from retail). Say I have a cost of $10.00, and I need the formula to calculate a 40% margin from retail. So the retail should end up at $16.67. Not sure how to get from $10.00 to $16.66, I just know the cost and the margin I need to make. Thanks JR =A1/(100%-40%) -- Kind regards, Niek Otten "JR" <gaspower@aol.com> wrote in message news:eGszf.424$2O6.53@newssvr12.news.prodigy.com... > Hello, > I need help with a margin forumla (calculated from retail). Say I have a > cost of $10.00, and I need the formul...

Excel 2007 PC damages Mac Excel 2008 Files
Version: 2008 Operating System: Mac OS X 10.4 (Tiger) Processor: Intel When I open a Mac Excel 2008 file on Excel 2007 and I can work with the file, however when the file is returned to the Mac, it no longer works correctly, leading to a crash as soon as I try to save or eventually it might change the file to look like a bunch of letters and characters. Here is the error report: <br><br>Microsoft Error Reporting log version: 2.0 <br><br>Error Signature: <br> Exception: EXC_BAD_ACCESS <br> Date/Time: 2010-01-15 17:05:56 -0600 <br> Application N...

GETPIVOTDATA data_field help
When I enter a reference to a cell, eg A2, as the value for the data_field item in the GETPIVOTDATA I get a #REF error. However, when I instead type the value of A2, eg 2003, manually into the GETPIVOTDATA formula, it works. Can anyone please help--I want this formula to vary based on what is in A2. Cheers This function is so variable in action, and difficult to handle, that have given it up in favour of VLOOKUP. In fact, having no problem i use with pivot tables -- Message posted from http://www.ExcelForum.com Try copying the headings from the pivot table, and pasting them into the ce...

Exchange server crashed, please help....! Need to restore two priv.edb and pub.edb files into one....!
Hi Guys, I was wondering if I could get some help with the following problem we are having on our company. Here is the scenario; Our Windows NT 4.0 SP4a server running Exchange 5.5 SP4 crashed (Server 1) due to the exchange database reaching its 16 Gig's max limit. I went ahead and moved some mailboxes' e-mails to a few .pst files in order to make some space. This worked ok. Then, I decided to build another exchange server (Server 2) to moved some mailboxes and alleviate the load. Once the server was ready and configured as part of the current exchange site, I went ahead and move...

Help!!!!
I am running Exchange 5.5 on NT 4.0 sp6a. Norton Anti- virus deleted my edb.log file. I have done an on-line restore with Arcserve 2000 and now my directory service won't start. getting 1166 internal processing error. I have been to support and could find anything that helped. Thanks in advance You may want to run eseutil /mh <drive and path to your dir.edb and include the dir.edb > c:\edb.dmp. Find this file and see if your dir is also inconsistent. If so you will need to restore your dir. -- Nan Bennett (MSFT) Microsoft Exchange Support Please do not send e-mail...

Install that important pack from the Microsoft Corp.
--xzkkhdmcbxymiaud Content-Type: multipart/related; boundary="vaccmkjzdr"; type="multipart/alternative" --vaccmkjzdr Content-Type: multipart/alternative; boundary="ggmepcujya" --ggmepcujya Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Microsoft User this is the latest version of security update, the "October 2003, Cumulative Patch" update which fixes all known security vulnerabilities affecting MS Internet Explorer, MS Outlook and MS Outlook Express. Install now to help maintain the security of your computer from these vulnera...

when opening an excel file, 2 files open (one is book1)?
When I click on an excel file, 2 excel documents open up. One document is called Book1 and the other document is the actual document that I want to open. How do I stop this from happening? Brian To prevent Book1 from opening you can append /e to your shortcut for opening Excel. "C:\PROGRAM FILES\MICROSOFT OFFICE\OFFICE\EXCEL.EXE" /e Alternative to the above............ Go to Start>Settings>Folder>Options>File Types. Scroll down to MS Excel Worksheet. Then if running Win98 OS Edit> select "Open" and Edit. If using WinXP OS you would scroll down to...

Continuing problmes with chkdsk and PST file
My PST file is apparently corrupted, with "Data error, cyclic redundancy check" upon starting Outlook. As per earlier advice, i ran chkdsk /r. But, chkdsk hangs. The % done on phase 4, file data check, was moving along at 1% per every 1 to 5 minutes. Then, at exactly 50%, it just stopped moving. I left it for a few hours, but no further progress (so i interrupted it). The disk light was on continually, but no progress in % complete. Also, if scanpst.exe is run, windows crashes (blue screen). So, are there any further suggestions? Is there any disk utility more robust t...

Numbering in Book Files
I am creating a tech manual where each chapter is its own file. I have created an outline numbered list and saved the list in a template that I then use to create the new chapters. However, I am finding that when I go into a new chapter that the outline numbering does not pick up on the chapter (Heading 1) number. For example: Chapter 1: Heading 1 style 1.1: Heading 2 style 1.1.1: Heading 3 style, etc. But when I start my next chapter, when I update the chapter number to start at 2, I get this: Chapter 2: Heading 1 style 1.1: Heading 2 style 1.1.1: Heading 3 style, etc. ...