Exporting to a text file Question

J

Joe Williams

I am interfacing with an external program and need to export table
information to a text file. The only caveat is that I need to export each
field of information onto a line by iteself. for example, if my comma
delimited information is (John, Doe, 123-45-6789, Supervisor) I need the
text file format to be:

john
does
123-45-6789
Supervisor

how do I export data to a text file, creating a new line for each seperate
field? I am only exporting one record at a time so delineation between
records is not needed in my case.

Thanks!

Joe
 
M

Marshall Barton

Joe said:
I am interfacing with an external program and need to export table
information to a text file. The only caveat is that I need to export each
field of information onto a line by iteself. for example, if my comma
delimited information is (John, Doe, 123-45-6789, Supervisor) I need the
text file format to be:

john
does
123-45-6789
Supervisor

how do I export data to a text file, creating a new line for each seperate
field? I am only exporting one record at a time so delineation between
records is not needed in my case.


Check Help for the file I/O statements, Open, Print #,
Close, etc.
 
F

fredg

I am interfacing with an external program and need to export table
information to a text file. The only caveat is that I need to export each
field of information onto a line by iteself. for example, if my comma
delimited information is (John, Doe, 123-45-6789, Supervisor) I need the
text file format to be:

john
does
123-45-6789
Supervisor

how do I export data to a text file, creating a new line for each seperate
field? I am only exporting one record at a time so delineation between
records is not needed in my case.

Thanks!

Joe

You need to do a bit of preliminary work first.

1) Create a query that will limit the records returned to just the one
you want with only the fields you want to export. Instead of dropping
the field names onto the grid, you need to create an expression that
will place a new line before each value, something like this:

SELECT YourTable.ID, Chr(13) & Chr(10) & [FirstName] AS Exp2, Chr(13)
& Chr(10) & [LastName] AS Exp3, Chr(13) & Chr(10) & [SSN] AS Exp4,
Chr(13) & Chr(10) & [Position] AS Exp5,
FROM YourTable
WHERE (((YourTable.ID)=113));

Notice a line space is added before each field (except for the first
field). Adjust the Where clause as needed to select the correct
record.

Save the query.

2) Select the query.
Click File + Export.

Follow the export wizard, selecting a Text Delimited file.
Write the text file name in the File name box and the file type as
".txt".
Click Export.
Click Advanced.
Set the File Format to Delimited, the space as Delimiter, and (none)
as Text Qualifier.
Save the specification under whatever name you choose. Let's say
"AddLines".

3) Click OK and the query will be exported to the file listed in the
dialog box.

4) After the above Export specification is created, here is the code
needed to run future exports:

DoCmd.TransferText acExportDelim, "AddLines", "QueryNameHere",
"c:\PathToFolder\YourDocName.txt"

The above will overwrite any previous text in YourDocName.
 

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