Creating TXT files based upon a Querry

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

Guest

I'm new to programming Access (and to programming in general) What I'm trying
to do is the following and I'm not exactly sure what is the best way to go
about doing it.

I have a querry that I need to export each record of as a seperate text
file. The text file itself will remain the same (i.e "foo.txt)" however the
path itself will change based upon 2 fields in the querry
(\\set\path\var1\var2\foo.txt)

Lastly I need the text file to be formatted like so:
blah=var1
blah=var2
blah=var3

Help Suggestions?
 
Hi,
it is not a complex task, if you are new to programming...
try to look at help samples of opening recordset, looping through it records
and how to output text file (Print # statement) - hope this will give you an
idea how to start
 
I usually do this sort of thing with the WriteToFile() function at
http://www.j.nurick.dial.pipex.com/Code/VBA/WriteToFile.htm. Provided
your security settings are not too stringent, you can call WriteToFile()
in a query, using fields or calculated fields as arguments, and it will
create the text files as a side effect of running the query.

For instance, this calculated field:

Result: WriteToFile([Contents], "C:\Temp\wtf\" & [Filename])

creates a textfile for each record in the query, placing it in the
specified folder, taking the filename from the [Filename] field and the
contents of the file from the [Contents] field.

It's up to you to use calculated fields in the query that format the
text the way you want it.
 
Back
Top