Here's a reusable procedure you can use to send each record to a file
as requested.
Sub WriteTextFileContents(Text As String, FileName As String, Optional
AppendMode As Boolean = False)
' A reuseable procedure to write or append large amounts of data to a
text file
Dim iNum As Integer, bIsOpen As Boolean
On Error GoTo ErrHandler
iNum = FreeFile()
If AppendMode Then Open FileName For Append As #iNum Else Open
FileName For Output As #iNum
'If we got here the file has opened successfully
bIsOpen = True
'Print to the file in one single step
Print #iNum, Text
ErrHandler:
'Close the file
If bIsOpen Then Close #iNum
If Err Then Err.Raise Err.Number, , Err.Description
End Sub 'WriteTextFileContents()
Watch for word wraps of single lines.
This is a very fast, self-contained procedure so you don't have to
include its code in other procs. Example:
<air code>
In your current proc:
Const sPath As String = "C:\Users\Steve\Desktop\New folder\output"
While Not oRS.EOF
xFilename = sPath & xFile & ".csv"
WriteTextFileContents oRS, xFilename
xFile = xFile + 1
Wend
If you want to parse the recordset into subsets first, do that and pass
the entire subset for the first arg. So, for example, to parse the
recordset into subsets of 10,000 you'd have to dump the data into an
array or string var delimited by vbCrLf. I think it would be faster to
load the data into a string var<IMO>.
<air code>
Dim i As Integer, sSubSet As String
Const sPath As String = "C:\Users\Steve\Desktop\New folder\output"
Const iMaxRows As Integer = 10000
While Not oRS.EOF
xFilename = sPath & xFile & ".csv"
For i = 1 To iMaxRows
sSubSet = sSubSet & oRS & vbCrLf: oRS.MoveNext
Next
WriteTextFileContents sSubSet, xFilename
xFile = xFile + 1
Wend
HTH
--
Garry
Free usenet access at
http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc