Solved

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

Posted on 2013-12-13
9
755 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
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
 
LVL 34

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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
Lync meeting or Lync conferencing is what many organizations would like to deploy to allow them save money. But companies are now giving up for various reasons, one of which is that they cannot join external meetings (non-federated company meetings)…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now