How many records are to be written?
You can try this:
Code:
Option Compare Database
Option Explicit
'requires a reference to
'Microsoft DAO 3.6 Object Library
'uses DAO 3.6
Public Sub ExportData()
Dim r As DAO.Recordset
Dim k As Integer
Dim sSQL As String
k = FreeFile
Open "OutputAllRecords.txt" For Output As #k
sSQL = "SELECT Field1 FROM Table1"
Set r = CurrentDb.OpenRecordset(sSQL)
If Not r.BOF And Not r.EOF Then
r.MoveLast
r.MoveFirst
Do While Not r.EOF
Print #k, r("field1");
r.MoveNext
Loop
Close #k
r.Close
Set r = Nothing
End If
MsgBox "done"
End Sub
No error handling
Text file name hard coded
Saves to a default directory.
Disclaimer: This code works for a recordset of 5 records. Your mileage may vary.