Solved

Import a .txt file into an Access .accdb file

Posted on 2014-09-16
3
717 Views
Last Modified: 2014-09-16
I have to import files of this nature on regular basis.
Going through the steps manually is quite straight forward.
I have tried a few ways with VBA, but can't succeed.
I attach a typical data file.
For me the most logic VBA is very simple:
   
DoCmd.TransferText acImportDelim, , "tblABC", "C:\MMI\" & "abc.txt", True

Open in new window

but that only imports the first field and gives an import errors table.
I attach my file and test database.
Please help.
Import-txt.accdb
abc.txt
0
Comment
Question by:Fritz Paul
  • 2
3 Comments
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 40326654
you need to create import specification first.

 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", "C:\folderName\myText.txt" , True
0
 

Author Closing Comment

by:Fritz Paul
ID: 40327334
Thanks Rey,
It works.
Where does Access store the ImportSpecificationName?
Can I export the specification to another database?
Can one edit the specification?
0
 

Author Comment

by:Fritz Paul
ID: 40327347
Hi Rey,
I see there are a lot of posts about above q's. So don't bother to answer.
Thanks again.
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

Suggested Solutions

Title # Comments Views Activity
table joins in qry 17 65
Access Schema 6 28
How to I Display a Date Text Box on a Form to show as dd/mm/yyyy? 6 21
Email Populated Report as PDF 2 15
When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
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.
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

820 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