Solved

Import a .txt file into an Access .accdb file

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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Tags from access to excel 3 28
Query to summarise data Like Pivot Table 3 29
Error in Rs.MoveNext & Duplication of Record 14 25
Access 2010 Query Syntax 5 22
Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
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…
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 …
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

910 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

23 Experts available now in Live!

Get 1:1 Help Now