Solved

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

Posted on 2013-12-13
9
771 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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
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

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.

Question has a verified solution.

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

User Beware!  This is a rather permanent solution to removing your email from an exchange server.  The only way to truly go back is to have your exchange administrator restore your mailbox from backups.  This is usually the option of last resort.  A…
Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

895 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

13 Experts available now in Live!

Get 1:1 Help Now