I am trying to iterate through a record-set twice. Once to write all of the non-zero results, followed by a second run through to write all the rows that have a zero in a particular column so that all of those rows with the value of 0 are at the end of the file. However since .EOF has been triggered with the first run through it is still “True” when I try to run through it again. What is the best way to run through it twice?
With CurrentDb.OpenRecordset(strSQL, dbOpenSnapshot)
Do Until .EOF
If .Fields(2) = 0 Then
Else
strCSV = ""
For x = 0 To .Fields.Count - 1
'No Qualifier
strCSV = strCSV & strDelimiter & Nz(.Fields(x), vbNullString)
Next x
'Eliminate Back to back strQualifiers or Qualifiers if changed
strCSV = Replace(strCSV, strQualifier & strQualifier, "")
strPrint = Mid(strCSV, Len(strDelimiter) + 1)
Print #intOpenFile, strPrint
End If
.MoveNext
Loop
Do Until .EOF
If Nz(.Fields(2), vbNullString) = 0 Then
strCSV = ""
For x = 0 To .Fields.Count - 1
'No Qualifier
strCSV = strCSV & strDelimiter & Nz(.Fields(x), vbNullString)
Next x
'Eliminate Back to back strQualifiers or Qualifiers if changed
strCSV = Replace(strCSV, strQualifier & strQualifier, "")
strPrint = Mid(strCSV, Len(strDelimiter) + 1)
Print #intOpenFile, strPrint
End If
.MoveNext
Loop
End With
To answer your question, just used
.MoveFirstin between your two runs. But @Remou makes a good point that your can avoid this complication just by adding anORDER BYinto your SQL (+1)