Solved

Import code for text file

Posted on 2014-09-30
3
334 Views
Last Modified: 2014-09-30
A few days ago an expert helped me with the importing of an Excel file into an Access database via:

DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, "tblTempFieldNotesImport", .SelectedItems(1), False, "A1:B66"

But now I need to do the same thing but with a tab delimited text file.

What should this line of code look like to do that?

--Steve
0
Comment
Question by:SteveL13
3 Comments
 
LVL 84

Assisted Solution

by:Scott McDaniel (Microsoft Access MVP - EE MVE )
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 167 total points
ID: 40352845
DoCmd.TransferText works much the same way:

DoCmd.TransferText acImportDelim, , "TableName", "FilePath"

More information here:
http://msdn.microsoft.com/en-us/library/office/ff835958(v=office.15).aspx
0
 
LVL 12

Assisted Solution

by:danishani
danishani earned 166 total points
ID: 40352853
Hi Steve,

You can use the DoCmd.TransferText () command for that.


Look for the link on how to use it.
DoCmd.TransferText Method (Access)
Basically the first time you can import the Text file manually and Save the Import Specification.
Then with the Command line you can specify the Import Specification and you can run it each time the same way.

Hope this helps,
Daniel
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 167 total points
ID: 40353167
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

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

831 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