TransferText

J

Jason Gyetko

When I run my export process using the TransferText method, it overwrites my
file every time it is run. Is there any way to get it to append to the
file? Here is what my code looks like:

DoCmd.TransferText acExportFixed, "File Export Specification", "MyTable",
"C:\TEMP\Export.txt"

Thanks.
 
K

Ken Snell

No. You'd need to use the VBA text file manipulations to do this:

Dim rst As DAO.Recordset
Dim strOutput As String
Set rst = CurrentDb.OpenRecordset("MyTable", dbOpenDynaset)
If rst.BOF = False And rst.EOF = False Then
Open "C:\TEMP\Export.txt" For Append As #1
rst.MoveFirst
Do While rst.EOF = False
' use code to concatenate the values from
' all the fields in the recordset into a single
' string variable strOutput. Example with
' using arbitrary widths of 20 and 10 for
' the first two fields):
strOutput = Left(rst.Fields(0).Value & Space(20), 20) & _
Left(rst.Fields(1).Value & Space(10), 10)
Print #1, strOutput
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
Close #1
 
G

Guest

If you link the text file, you can append rows to it. You cannot update rows in a linked "flat" file but you can append to them either by typing values into a datasheet or form or by running an append query.
 

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

Similar Threads


Top