Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems formatting text file generated from using OutputTo Method

Status
Not open for further replies.

nancylynn

Programmer
Apr 16, 2002
9
US
Using Access 2000-
I am using the OutputTo method on a form, but when it exports the data, the data is formatted with all these borders around each piece of data. All I need is a comma delimited text file to be exported, without including the field names. Only the data in the recordset. Here is the code I have currently:

Private Sub Form_Dirty(Cancel As Integer)
DoCmd.OutputTo acOutputForm, "frmTest", acFormatTXT, "test.txt"
End Sub
 
Instead of using DoCmd.OutputTo, try using DoCmd.TransferText, as follows:
Code:
DoCmd.TransferText acExportDelim, , Me.RecordSource, "C:\Temp\Test.txt", False
This will produce a comma delimited version of your form's record source with no field lables in the first record.
 
Thanks! That works great. Now I need to get rid of the space between quotes (from null values). I need the exported data to look like this:
"33338","doe","nancy","","2"
instead of this:
"3338","doe","nancy"," ","2"
 
You'll get a blank between the quotes for a field that actually has a blank stored in the database. The TransferText command cannot change the stored data on the fly.

If you don't want to change the database contents for the export, you could write a query based on your form's record source that checks for blanks in a field and substitutes a null string. For example:
Code:
Expr1: IIf([Field4]>" ",[Field4],"")
Then, use the query as your export record source in the TransferText command. For example:
Code:
DoCmd.TransferText acExportDelim, , "qryMyFormNoBlanks", "C:\Temp\Test.txt", False
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top