Export fields into new text files

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I need to create a series of small text files using the contents of fields as
file names and contents. The source table ("tblSource") has two fields,
"strFilenam" and "strText". Each "strText" entry needs to become its own
separate file named something like strFilenam.txt. I have tried
DoCmd.OutputTo and TransferText, but keep failing to find a combination that
will create separately-named files.
 
You need to loop through the records, creating a new file and writing to it
for each record. See FileSystemObject object and CreateTextFile, WriteLine
methods in the VB help.
 
The WriteToFile() function at
http://www.j.nurick.dial.pipex.com/Code/index.htm
does what you ask.

If your computer's security settings allow, you can use an expression like
this in a SELECT query:

WriteToFile([strText], [strFilenam] & ".txt")

The query will show the return values from WriteToFile, and the files get
created as a side-effect.

Alternatively, open a recordset on the table and iterate through it in the
usual way.
 
Back
Top