Solved

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

Posted on 2014-09-13
9
463 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
[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
  • 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
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.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

740 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