Solved

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

Posted on 2014-09-13
9
462 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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 
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

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.

Question has a verified solution.

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

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.
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Familiarize people with the process of utilizing SQL Server stored procedures 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 Micr…
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…

756 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