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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Importing Multiple Text files in Acc 97

Status
Not open for further replies.

mike67

Technical User
Apr 8, 2002
8
0
0
US
I searched the posts so far on this subject and haven't been able to pull together all the pieces I need. I have a directory of about 50 txt files I want to import into an existing Access table. There is one extra field in the table (the last field in table, in doing manual importing I was simply changing the default value of this field to reflect the filename) in which I would like to place the filename on each record.

It seems the TransferText method would be the easiest approach but do not know how to include the filename as part of the equation. Any suggestions? [bigears]
 
Hi

in pseudo code

For each file get file name (dir Function)
Transfertext
setwarnings off
runsql to set file name where file name is blank
set warnings on
next file name

Do you need more precise code than that? Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
UK
 
Ken,

Thanks for the tip. I'm just learning some of the basics of programming in Access and will give it a shot.

What is the best way to loop through all files in a directory? I know the number of files at any given time so I could change the variable with each run, but is there an easy way of looping through all files in a directory until there are no more?

Thanks again for your help!

Mike
 
Hi

Basically

Dim FileName As String
FileName = Dir(*.txt)
Do Until FileNmae = ""
...do your thing here
dir
Loop

see dir() in help for various switches )ie look for file, look for directories (folders) etc

Hope this helps Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
UK
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top