Here's some code that I used. Note that Chr$(34) is a double-quote. This
should output everything surrounded by a double-quote. If it doesn't, add an
extra " & Chr$(34)" or even """ (3 double-quotes) where you need it:
Function MakeTextFile()
On Error GoTo Error_Handler
Dim db As Database
Dim rst As DAO.Recordset
Dim strSQL As String
Dim qdef As QueryDef
Set db = CurrentDb
Set qdef = db.QueryDefs("qryWhatever")
If Not IsNull(Me.txtFileName) Then
Me.txtFilePath = ""
Set rst = qdef.OpenRecordset
rst.MoveFirst
Open "S:\POFiles\" & "PO-" & Format(Date, "mmddyy") & ".txt" For Append
As #1
Print #1, Chr$(34) & "*" & Chr$(34) & "," & Chr$(34) & Me.txtFileName &
Chr$(34) & _
"," & Chr$(34) & Me.txtFileName & Chr$(34) & "," & Chr$(34) & Chr$(34) &
"," _
& Chr$(34) & Chr$(34) & "," & Chr$(34) & Chr$(34) & "," & Chr$(34) &
Chr$(34) & "," _
& Chr$(34) & Chr$(34) & "," & Chr$(34) & Chr$(34) & "," & Chr$(34) &
Chr$(34) & "," _
& Chr$(34) & Chr$(34) & "," & Chr$(34) & Chr$(34) & ",," & Chr$(34) &
Chr$(34) & "," _
& "1," & Chr$(34) & Chr$(34) & "," & Chr$(34) & Chr$(34)
Do Until rst.EOF
Print #1, Chr$(34) & "C" & Chr$(34) & "," & Chr$(34) &
Format(rst!CostCode, "0.000") & Chr$(34) & "," _
& Chr$(34) & Space(30) & Chr$(34) & "," & Chr$(34) & "S " & Chr$(34) &
"," _
& Format(Date, "mmddyyyy") & ",0.00," & Chr$(34) & Chr$(34) & "," &
rst!FormatCost _
& ",,1," & Chr$(34) & Chr$(34) & "," & Chr$(34) & Chr$(34)
rst.MoveNext
Loop
Close #1
MsgBox "Done!"
End If
Exit_Here:
Exit Function
Set qdef = Nothing
rst.Close
Set rst = Nothing
Set db = Nothing
Error_Handler:
MsgBox Err.Number & ": " & Err.Description
Close #1
Resume Exit_Here
End Function