Function exportQuery()
Dim trz As Integer
Dim strCSV As String
For trz = 1 To 511
Close #trz
Next trz
trz = FreeFile
Open "C:\Users\NAME\Documents\qry_tblMAIN.csv" For Output Access Write As #trz
With CurrentDb.OpenRecordset("qry_tblMAIN ")
Dim x As Integer
For x = 0 To .Fields.Count - 1
strCSV = strCSV & strColumnDelimiter & .Fields(x).Name & ", "
Next x
Print #trz, Mid(strCSV, Len(strColumnDelimiter) + 1)
Do Until .EOF
strCSV = ""
For x = 0 To .Fields.Count - 1
strCSV = strCSV & strColumnDelimiter & Nz(.Fields(x), "") & ", "
Next x
Print #trz, Mid(strCSV, Len(strColumnDelimiter) + 1)
.MoveNext
Loop
End With
Close #trz
End Function