Sub oTestExport() OutputToText ("Select * From t_Arms") End Sub Function OutputToText(ByVal oSQL As String) Dim Recordset As DAO.Recordset Dim mfile As Integer Dim strLine As String Dim oPathAndFile As String: oPathAndFile = CurrentProject.Path & "\" & "Text.txt" strLine = vbNullString Set rst = CurrentDb.OpenRecordset(oSQL, dbOpenSnapshot) mfile = FreeFile 'Returns value of 1 'Open "C:\Temp\Recordset.txt" For Output As #mfile Open oPathAndFile For Output As #mfile 'headers For i = 0 To rst.Fields.Count - 1 strLine = strLine & rst.Fields(i).Name & "," Next strLine = Left(strLine, Len(strLine) - 1) Print #mfile, strLine With rst While Not .EOF strLine = vbNullString For i = 0 To .Fields.Count - 1 strLine = strLine & rst.Fields(i) & "," Next strLine = Left(strLine, Len(strLine) - 1) Print #mfile, strLine .MoveNext Wend Close #mfile End With End Function
Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.
”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.
Our community of experts have been thoroughly vetted for their expertise and industry experience.
The Distinguished Expert awards are presented to the top veteran and rookie experts to earn the most points in the top 50 topics.