Solved

Import a .txt file into an Access .accdb file

Posted on 2014-09-16
3
658 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 119

Accepted Solution

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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
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 …
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…

708 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

13 Experts available now in Live!

Get 1:1 Help Now