PC Review


Reply
Thread Tools Rate Thread

Carriage returns inside an exported CSV file data field.

 
 
Badroy
Guest
Posts: n/a
 
      28th Jan 2006
I am exporting orders from a Access database connected to a website.
The problem is when I export to a CSV sometimes it generates carriage
returns inside the data field. This ruins the import process into
another database which can be automated. I have to manually open the
text file and strip any carriage returns costing me time.

Is there a way in access to strip these?

"John ""Da Man""",Repici,120 Jefferson St.,Riverside, NJ,08075 <----
unwanted carriage return here
Stephen,Tyler,"7452 Terrace ""At the Plaza"" road",SomeTown,SD, 91234
,Blankman,,SomeTown, SD, 00298

 
Reply With Quote
 
 
 
 
Dirk Goldgar
Guest
Posts: n/a
 
      28th Jan 2006
"Badroy" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)
> I am exporting orders from a Access database connected to a website.
> The problem is when I export to a CSV sometimes it generates carriage
> returns inside the data field. This ruins the import process into
> another database which can be automated. I have to manually open the
> text file and strip any carriage returns costing me time.
>
> Is there a way in access to strip these?
>
> "John ""Da Man""",Repici,120 Jefferson St.,Riverside, NJ,08075 <----
> unwanted carriage return here
> Stephen,Tyler,"7452 Terrace ""At the Plaza"" road",SomeTown,SD, 91234
> ,Blankman,,SomeTown, SD, 00298


I don't know for sure, but I suspect that the fields actually have
carriage returns that were entered by users. If you can't remove them
from the input before they get into the database, you could export a
query that strips them out, using the Replace function. If you're
actually working in Access, you could write a function like this:

'----- start of code -----
Public Function NoCR(SourceField As Variant) As Variant

If Not IsNull(SourceField) Then
NoCR = Replace(SourceField, vbCrLf, "", , , vbBinaryCompare)
End If

End Function
'----- end of code -----

Then your query could wrap each field -- or each field that is subject
to this problem -- in a call to the function; e.g.,

SELECT
FirstName,
LastName,
Address,
City,
State,
NoCR(Zip)
FROM
YourTable;

If you export that query instead of the table itself, the carriage
returns should be stripped from the Zip field.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


 
Reply With Quote
 
Badroy
Guest
Posts: n/a
 
      29th Jan 2006
I am fairly new to access so I am guessing that functions can be
defined in modules. Since I get this error in multiple data fields
(mostly text related) would I do this in the query?

SELECT
NoCR(FirstName),
NoCR(LastName),
NoCR(Address),
NoCR(City),
State,
NoCR(Zip)
FROM
YourTable;

 
Reply With Quote
 
Dirk Goldgar
Guest
Posts: n/a
 
      29th Jan 2006
"Badroy" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)
> I am fairly new to access so I am guessing that functions can be
> defined in modules.


Right. I'd suggest storing the NoCR() function in a standard module,
probably one that you create (or have already created) for the purpose
of holding various utility procedures. One point to remember, if you're
not familiar with modules and VBA, is that the name of the module must
not be the same as that of any of the functions it contains. Give the
module its own, unique name.

> Since I get this error in multiple data fields
> (mostly text related) would I do this in the query?
>
> SELECT
> NoCR(FirstName),
> NoCR(LastName),
> NoCR(Address),
> NoCR(City),
> State,
> NoCR(Zip)
> FROM
> YourTable;


Yes, though I see I failed to suggest an alias for the new calculated
field. If you don't want these fields to show up in your queries as
"Expr0001", "Expr0002", and so on, you'd best provide names for them;
e.g.,

SELECT
NoCR(YourTable.FirstName) As FirstName,
NoCR(YourTable.LastName) As LastName,
NoCR(YourTable.Address) As Address,
NoCR(YourTable.City) As City ,
State,
NoCR(YourTable.Zip) As Zip
FROM
YourTable;

Note that I added the "YourTable." qualifiers so that I could reuse the
same name without confusing the SQL engine with an apparently circular
reference.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


 
Reply With Quote
 
Badroy
Guest
Posts: n/a
 
      29th Jan 2006
Thank You

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Importing Text with Carriage Returns inside cell values Ryan L Microsoft Excel Misc 2 14th May 2009 08:58 PM
Importing Text with Carriage Returns inside cell values Ryan L Microsoft Excel Misc 0 14th May 2009 07:34 PM
Removing carriage returns from a address field Matt Microsoft Access Form Coding 1 8th Jul 2008 12:41 PM
Carriage returns in exported text file john123allen@yahoo.com Microsoft Access 4 19th Mar 2007 10:23 PM
c# export to excel and preserve carriage returns inside cell Bryan Ax Microsoft C# .NET 0 19th Jul 2006 11:14 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:22 AM.