EXPORT into txt files

H

Hec

I have a table containing data that should be exported into txt
files.A table looks like this :

DOC_NUMBER EAN ART_ID
500001 4004711729003 004457
500001 4082800110109 004392
500002 4082800699444 004397
500002 4082800699710 003927
500002 3386463302705 003271
500003 4004711242403 002789
500003 4004711243301 004631

I need to export this data into saparate txt files. A rows with a
document number 500001 shuld be exported into txt file with a name
O500001.txt, rows with a document number 500002 should be exported
into txt file with a name O500002 and so on.
Is it possible to do this?

Any help would be great.
 
N

Nikos Yannacopoulos

Hec,

This is a piece of cake with a fiew lines of VBA code like the following
example:

Sub Export_Text_Files()
Dim rst As DAO.Recordset
Dim FolderName As String
Dim FileName as String

FolderName = "C:\Temp"
Set rst = CurrentDb.OpenRecordset("TableName")
rst.MoveFirst
Do Until rst.EOF
FileName = FolderName & "\O" & rst.Fields(0) & ".txt"
Open FileName For Output As #1
Print #1, rst.Fields(1), rst.Fileds(2)
Close #1
rst.MoveNext
Loop
rst.Close
set rst = Nothing
End Sub

Change C:\Temp to your preferred destination folder;
Change TableName to the actual table name;
From within the VBA window, go to menu Tools > References and tick next to
Microsoft DAO 3.x Object Library. Select DAO 3.6 for Access2K or later, DAO
3.51 for Access97.

If the file format is not what you want (you did not specify), post back -
or try to modify hte Print statement to get what you want.

HTH,
Nikos
 

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