Solved

Remove CRLf in Access Table fields

Posted on 2014-01-04
14
1,216 Views
Last Modified: 2014-01-06
I have an Access database with a table that has CRLf characters in several columns; 4 to be exact. These are text fields ( I think limited to 200 characters). I need to export this table to a tab delimited text file that I can use to import into a MySQL database.

In working with an EE Expert, it was suggested that I use this Access coding to remove these; this is an example in ONE of the 4 columns (ServiceComments1): Replace(Replace(Nz([ServiceComments1],""),Chr(10)," "),Chr(13)," ")

I did this & the CRFf's are still in the middle of some of the instances, same as before with NO Replace.

Also, prior to doing the Replace, I did a search, Find of chr(10), Chr(13), Vbcr and vblf on the columns; none found in ANY case.

I might be able to edit this out in the resultant text file bu it is tedious & requires it be manually done for over 100 records in total.

Is there a way I can get this done in Access BEFORE I export the table?

Thanks
0
Comment
Question by:Richard Korts
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 3
  • +1
14 Comments
 
LVL 40

Expert Comment

by:als315
ID: 39756424
Can you upload DB with some sample records?
0
 
LVL 6

Expert Comment

by:r3nder
ID: 39756429
string s = string.Empty;
s = replace(s, vbcrlf, " ") 'if it's a CR/LF pair
or

 s = replace (s, chr(10), " " 'if it's just a Line Feed
 or

 s = replace (s, chr(13), " " 'if it's just a Carraige Return
0
 
LVL 38

Expert Comment

by:PatHartman
ID: 39756575
If you post a database with just the table in it holding a couple of records that create multiple records on export, I will examine the table with a hex editor to see what character is actually causing the problem.  Make sure to obscure anything sensitive.

What exactly is the output format you need?  Do you have any flexibility?  A csv file with quoted text fields eliminates the problem of the extraneous crlf's.
0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

Author Comment

by:Richard Korts
ID: 39756591
I did a search (in Access) for vbcrlf; no match.

Previous search shows no match for chr(10) or chr(13).

See attached.

I will try to build a small single table Access database of JUST some of the problem records. It will be a struggle for me because the problem records (obviously) are NOT contiguous.

I am trying to produce a TAB delimited txt file (readable by Excel). I choose this format because data often contains commas, thus csv doesn't work.

Thanks
cant-find-vbcrlf.jpg
0
 
LVL 38

Expert Comment

by:PatHartman
ID: 39756613
As I told you in the other thread, csv DOES work if you select the option to surround the text fields with quotes.  The quotes handle embedded commas but do not solve the problem of CrLf which users frequently put in their text.  There are other characters which could be causing the problem which is why I would like more than one example.
0
 

Author Comment

by:Richard Korts
ID: 39756802
Attached is an excel export of a small portion of the table. The fields that have the CRLF problem within the field are ServiceComments 1, ServiceComments2, Comments1 & Comments2.

In this small sample the only ones that have this issue are the ones with Key 10034, 10048, 10059 & 10082. I do NOT know which of the 4 fields has the problem, but in those 4 records, at least ONE does.

I could not figure put how to build a query & then export to Access; it says you can, but it didn't work.

If you have to have Access, tell my how to export a SMALL portion of a large table into Access. It might be that exporting it to Excel fixes the problem; if it does, I can work with that too.

Thanks
sample1.xlsx
0
 
LVL 6

Expert Comment

by:r3nder
ID: 39756877
can you make me an empty acess db with a table and the fields - Thanks
0
 
LVL 38

Expert Comment

by:PatHartman
ID: 39757000
There is no problem with the Excel Export.  No additional records were created.

Create a make table query.

SELECT yourtable.*  INTO tempTable
FROM yourtable
WHERE Key = 10034 OR Key = 10048 OR Key = 10059 OR Key = 10082;

Then create a new empty database and import only tempTable.
0
 
LVL 40

Accepted Solution

by:
als315 earned 500 total points
ID: 39757013
I don't see any errors in your logic. Look at sample with imported Excel table (Sheet1).
QueryFind show all records with CrLF (4 records, as expected in ServiceComment1 - 2 records and in Comment1 - also 2). QueryUpd replace CrLF with space. Look at sample
DBCRLF.accdb
0
 

Author Comment

by:Richard Korts
ID: 39759704
To als315,

I looked at your query design; I accidentally ran your update query, then I ran the find, it finds nothing, which I THINK is good.

You query design has a row called Update To: Mine does not. How do I get that row inserted into design view?

Thanks
0
 
LVL 40

Expert Comment

by:als315
ID: 39759985
You should change type of query to update query and manually add "update to" string
update query
0
 

Author Comment

by:Richard Korts
ID: 39760049
To als315,

The Update Query actually changes the content of the table, is that correct? I ran it & it said it updated some 12000 records.

Thanks
0
 
LVL 40

Expert Comment

by:als315
ID: 39760111
Yes, table should be updated, now you can search CrLf in your table
0
 

Author Closing Comment

by:Richard Korts
ID: 39760156
Works perfectly!!

Thanks so much, I thought I would NEVER overcome this.
0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

622 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question