Solved

Importing text file to Access - ADO preemptively interprets a text column as date datatype

Posted on 2014-09-13
9
449 Views
Last Modified: 2014-09-13
We have an Access application with a SQL Server database for a testing laboratory. We are importing text files from an Agilent ICPMS instrument (sample attached). The Sample Name column is a text field of the format wwww-xxx-y. That matches a primary key in a main table in the SQL Server database. Examples:
1409-002-01, 1409-013-1, 1409-096-1. The first two look like dates to ADO and it reformats the data as such.

We're using this connection info:
    objconnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strPathToTextFile & ";Extended Properties=""Text;HDR=YES;FMT=Delimited"""
    objRecordset.Open "SELECT * FROM [" & ThisFileName & "]", objconnection, adOpenStatic, adLockOptimistic, adCmdText 'select all text lines from the file

I have tried renaming the file as .txt. Same problem.

How can I force ADO to NOT HELP with interpreting the Sample Name values as dates?
G--GSAJDrive-InstrumentOutputFiles-ICPMS
0
Comment
Question by:dmaclean2
  • 5
  • 4
9 Comments
 
LVL 119

Assisted Solution

by:Rey Obrero
Rey Obrero earned 500 total points
ID: 40321001
have you tried using "Import Specification" to import the text file?


 To create the Import Specification
 1) Click on external data> text file which then opens another window called "Get external data - Text file"
 2) Use radio button to select "Import the source data into a new table in the current database"
 3) specify the source of the file using the browse procedure then click OK
 4) Choose radio button to select delimited format and then click next
 5) this window allows you to choose delimiter and text qualifier and if first row contains names - click next
 6) This window allows you to type the name of the field in the Field Name column, choose data type, and if you want field indexed - also can choose to skip field - then click next
 7) This window allows you to add primary key or designate field as such - click next
 8) Click on ADVANCED button
 9. in the import specification window
 type the name of the field in the Field Name column
 (here you can use the field names of the destination table, specify data type,
 check the box Skip if you do not want to import the column)
 10 click save as, give the specification a name <-- this is the specification name that you will use in the command line below

 DoCmd.TransferText acImportDelim, "ImportSpecificationName", "TableName", Returnvalue, blnHasFieldNames
0
 

Author Comment

by:dmaclean2
ID: 40321015
Interesting idea, Rey,

I'll try it and let you know. Thanks
Doug
0
 

Author Comment

by:dmaclean2
ID: 40321055
OK. The good news is that it produces the right results.

Now, the trick is that my VBA code loops through all the text files in a specified folder and imports each of them. So I need to dynamically modify the import specification details on the fly.

How can I find that actual import specification that I created and turn it into VBA code that I can make dynamic?

The context is that the user clicks a button that says "Process Files". The user's only responsibility is to have put one to n files from the ICPMS instrument into a specified folder ready to be processed.
0
 
LVL 119

Assisted Solution

by:Rey Obrero
Rey Obrero earned 500 total points
ID: 40321074
you will need one specification file for "ALL" text file that have the same format.

how many different file format do you have?
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 

Author Comment

by:dmaclean2
ID: 40321086
One format, exactly like the sample I attached
0
 
LVL 119

Assisted Solution

by:Rey Obrero
Rey Obrero earned 500 total points
ID: 40321095
you can reuse the ImportSpecification for all your files, using this format

DoCmd.TransferText acImportDelim, "ImportSpecificationName", "TableName", strPathToTextFile & "\" & filename , True
0
 

Author Comment

by:dmaclean2
ID: 40321143
OK. That's good.
So, the import spec I saved is buried in the .accdb file somewhere and I don't need to see it and deal with it directly. Right?
0
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 500 total points
ID: 40321170
that is correct, you just need the name of the import spec.
0
 

Author Closing Comment

by:dmaclean2
ID: 40321212
This is a great solution. Thanks much for your guidance.
0

Featured Post

What Security Threats Are You Missing?

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

Suggested Solutions

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

757 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

18 Experts available now in Live!

Get 1:1 Help Now