Solved

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

Posted on 2014-09-13
9
457 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:Douglass MacLean
  • 5
  • 4
9 Comments
 
LVL 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) 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:Douglass MacLean
ID: 40321015
Interesting idea, Rey,

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

Author Comment

by:Douglass MacLean
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
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
LVL 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) 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
 

Author Comment

by:Douglass MacLean
ID: 40321086
One format, exactly like the sample I attached
0
 
LVL 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) 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:Douglass MacLean
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 120

Accepted Solution

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

Author Closing Comment

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

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

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…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
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 …

770 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