Solved

MS ACCESS 2010 - import a CSV with character numeric data "=""123"""

Posted on 2013-12-13
9
832 Views
Last Modified: 2013-12-21
I have a CSV file with character numeric data.
I would like to import it into MS ACCESS.
The format doubleQuote and equals sign in front of two doubleQuotes at the front and three double quotes after each field.
here is an example:
Field1,Field2,Field3
"=""013""","=""0133530670-01""","=""0010000101847"""

This format allows the CSV to be opened in Excel nicely with each field contain numbers, left justified as "characters".

How can I import them into MS ACCESS 2010.
I've tried using an import specification with comma delimiter and double quote " as the separator.
When I do that, I get values like
="013"

thanks!
Phil
0
Comment
Question by:philkryder
[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
9 Comments
 
LVL 21
ID: 39718142
The way I always import in to import the data into a temp/work table. This give me a chance to "scrub" the data before appending it tot he final destination.

Once you have the imported into text fields you can run an update query to scrip off the =.
0
 
LVL 3

Expert Comment

by:0Doc
ID: 39718144
I was able to get this to work with 2013, I assume 2010 will be the same.  What I did was take off the extra double-quotes, so that the data was shown just like you want it to import.  
="013",="0133530670-01","=0010000101847"
Then during the import, set the Delimiter as Comma and the Text Qualifier to None
Give that a try,

0Doc
0
 
LVL 21
ID: 39718151
TIP: Don't assume backward compatibility between versions. I find that you generally can expect things to work in newer versions.

I did a test and import the data first into a table as text fields. I ran an update query using:

Mid(Replace([MyFiledNameHere],Chr(34),""),2)

Open in new window


Concept test results:
strNum = "=""123"""
? strNum
="123"
? Mid(Replace(strNum,Chr(34),""),2)
123

Open in new window

0
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
LVL 37

Accepted Solution

by:
PatHartman earned 500 total points
ID: 39718276
If you can change the file format to the standard of comma delimited with text in double quotes, it will import into Access using TransferText.  With a non-standard format, you either need to import it using VBA where you examine the file character by character or sometimes you can import it and then fix it up later with queries.

In a standard format, the record would be:
"013","0133530670-01","0010000101847"
0
 
LVL 38

Expert Comment

by:Jim P.
ID: 39720312
Try this:

Public Function Q_28318074()

Dim FileNum As Integer
Dim InputFile As String
Dim InputString As String
Dim I As Integer
Dim StringArray() As String

Dim DB As Database
Dim RS As Recordset
Dim SQL As String

'Opening the table to write to
Set DB = CurrentDb()
Set RS = DB.OpenRecordset("MyTableName")    '<-- Change to your tablename

'Opening the file to read from
FileNum = FreeFile()
InputFile = "C:\MyFolder\MyTextFile"        '<-- Change to your folder and path
Open InputFile For Input Access Read Shared As #FileNum

I = 0

Do Until EOF(FileNum) = True
    Line Input #FileNum, InputString            'Read the data in
    StringArray = Replace(Split(InputString, Chr(44)), Chr(34), "")
    
    With RS                                 'the input is an empty string write it
        .AddNew
        For I = 0 To (UBound(StringArray) - 1)
        .Fields(I).Value = StringArray(I)
        Next I
        .Update
    End With
    I = 0
Loop

RS.Close

Set RS = Nothing
Set DB = Nothing
Close #FileNum

End Function

Open in new window

0
 
LVL 1

Author Comment

by:philkryder
ID: 39732539
I loaded the data with the extra characters and then stripped them in an update query.
It worked.
I was hoping there was a way to make the specification do it.
but, sadly, no.
0
 
LVL 38

Expert Comment

by:Jim P.
ID: 39732580
I was hoping there was a way to make the specification do it.

Just a note: I went away from using Import/Export specs years ago. There was one too many database corruptions that the spec was lost or had to be recreated from memory. I found that I could build a basic VBA function to do the same thing. Even some generic functions that  could accept different delimiters.
0
 
LVL 21
ID: 39734173
Did you ended up using my suggestion?

I was hoping there was a way to make the specification do it.
but, sadly, no.

Like jimpen, I rarely (almost never) use the import specs.. It works best with very "clean" data. Unfortunately data is reraly "clean". That is why I import into a temp/work table.
0
 
LVL 38

Expert Comment

by:Jim P.
ID: 39734190
Unfortunately data is rarely "clean".

I had one text file that the Ops team was importing that came from an IBM or *nix format. It would have multiple EOF characters that would choke in a Win/DOS environment; but not be there every time.

I had to build a character by character import that found if the EOF character occurred before the true end of the file (hint it was based on file sizes v. character count) and have the operator do a search and replace on the text file.

I wonder what a newbie Access dev using an IMEX spec would have done with it?
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Having trouble getting your hands on Dynamics 365 Field Service or Project Service trial? Worry No More!!!
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

726 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