Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Importing a text file using VBA 2

Status
Not open for further replies.

itechC

Programmer
Feb 13, 2003
71
CA
Hi all,

I would like to import data from a text file into my access database using vba. I have alot of text files to import so i would like to automate it. Any ideas how to go about doing this. The data is sererated by commas.
 
Use this code to import:

DoCmd.TransferText acImportDelim, , TableName, FileName
 
I tried that and it tells me "The search key was not found in any record"

here is a copy of my code:
Sub ImportTxtFile()

Dim vPath As String
Dim vTableName As String

vTableName = "catering"
vPath = "C:\Documents and Settings\Frank\My Documents\" & vTableName

DoCmd.TransferText acImportDelim, , vTableName, vPath

End Sub
 
Ok i added the extension to the file name (txt). It imports the file but only the first info before the ;.
Example:
Thisis what the file that i want to import look like:
"ABC GOURMET CATERING";"";"";"916450132";"CALLE TORRES QUEVEDO, 4";"MOSTOLES";"MOSTOLES";"28936";"MADRID"

I only get ABC GOURMET CATERING in my access table.
 
Ok,

You will need to create a SpecificationName to tell access that the delimiter identifier is ";" not "," to get it to import properly.

To do this select any table and choose File->Export

When the prompt opens change the save as type to Text Files

When the export text wizard opens click on the advanced button. Change the Field Delimiter to ";" then click on the save as button. Enter the name you want for that spec and change your code to this:

DoCmd.TransferText acImportDelim,SpecName,TableName,FileName

HTH
 
Thats exactly what i did and i still get only the title of the record i want to import. My table only gets populated with one field.

Sub ImportTxtFile()

Dim vPath As String
Dim vTableName As String
Dim vSpecName As String

vTableName = "catering"
vPath = "C:\Documents and Settings\Frank\My Documents\IT Data Direct\Spain\Spain Data\" & vTableName & ".txt"
vSpecName = "Spain Export Specification"

DoCmd.TransferText acImportDelim, vSpecName, vTableName, vPath

End Sub

Any other ideas??
 
if I import it manually by clicking on the semi-colon as my text delimeter it works fine.When i load my specification it gives me only the title.
 
I can't find the advanced feature when I click the export. HELP!! thanks.
 
Make sure you put the import specification name in quotes or it won't recognize it.
 
Hey,
mgolla, your answers in this post were exactly what I needed for a current project!

Thanks! have a star!

Stephen [infinity]
"Jesus saith unto him, I am the way, the truth, and the life:
no man cometh unto the Father, but by me." John 14:6 KJV
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top