Import a txt file.

  • Thread starter turks67 via AccessMonster.com
  • Start date
T

turks67 via AccessMonster.com

How to import a txt file into a table in access from a command button?
 
D

Dorian

You need the 'TransferText' command. Look it up in Access Help for all the
information and examples you could want.
You will need to set up an event procedure for the command button to run
your TransferText command.
-- Dorian
"Give someone a fish and they eat for a day; teach someone to fish and they
eat for a lifetime".
 
R

ryguy7272

This will import multiple .txt files into a Table; if you only have one .txt
file then the end result should be the same...and if you want to import
several files someday you have it when you need it...

Sub ImportAllExcelFiles()

On Error GoTo Err_F

Dim strPathFile As String, strFile As String, strPath As String, strSpec As
String
Dim strTable As String, ynFieldName As Boolean
ynFieldName = False
strPath = "C:\Documents and Settings\ThinkPad\Desktop\Import\"
'strSpec = "NameOfImportSpecification" ' Put your name here
strTable = "tablename"
strFile = Dir(strPath & "*.txt")
Do While Len(strFile) > 0
strPathFile = strPath & strFile
DoCmd.TransferText acImportDelim, strSpec, strTable, strPathFile, ynFieldName
' Uncomment out the next code step if you want to delete the file after it's
imported
' Kill strPathFile
strFile = Dir()
Loop
Exit_F:
Exit Sub

Err_F:
MsgBox Err.Number & " " & Err.Description
Resume Exit_F

End Sub

Regards,
Ryan---
 
T

turks67 via AccessMonster.com

I will try this. Thanks for helping me, reading books trying to understand
this.
 
T

turks67 via AccessMonster.com

What is the ynFieldName and the NameOfImportSpecification? Thanks
 
T

turks67 via AccessMonster.com

I'm getting This error "2391 Field 'F1' doesn't exit in destination table
'tbldurtotals1'. What am I missing.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top