Good Afternoon
The following code creates a .csv file.
The output looks something like this
Peter, Pan, 20, Male,
Mary, Pan, 20, Female,
John, Doe, 40, Male,
The problem is the last comma on each row. It should no be there. Or I need to delete it.
I can't figure out how to remove the last comma character from each row. Do you have any suggestions?
Function Process_CSV()
'Export csv file
Dim trz As Integer
Dim strCSV As String
For trz = 1 To 511
Close #trz
Next trz
trz = FreeFile
Set fso = CreateObject("Scripting.FileSystemObject")
folderFilePath = "C:\MyDocuments\"
Open "C:\MyDocuments\MyFile.csv" For Output Access Write As #trz
With CurrentDb.OpenRecordset("tbl_TEMP_ARCHIVE_ASSETS")
'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), "") & ", "
strCSV = StrConv(strCSV, vbUpperCase)
Next x
Print #trz, Mid(strCSV, Len(strColumnDelimiter) + 1)
.MoveNext
Loop
End With
Close #trz
End Function
Thank You
The following code creates a .csv file.
The output looks something like this
Peter, Pan, 20, Male,
Mary, Pan, 20, Female,
John, Doe, 40, Male,
The problem is the last comma on each row. It should no be there. Or I need to delete it.
I can't figure out how to remove the last comma character from each row. Do you have any suggestions?
Function Process_CSV()
'Export csv file
Dim trz As Integer
Dim strCSV As String
For trz = 1 To 511
Close #trz
Next trz
trz = FreeFile
Set fso = CreateObject("Scripting.FileSystemObject")
folderFilePath = "C:\MyDocuments\"
Open "C:\MyDocuments\MyFile.csv" For Output Access Write As #trz
With CurrentDb.OpenRecordset("tbl_TEMP_ARCHIVE_ASSETS")
'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), "") & ", "
strCSV = StrConv(strCSV, vbUpperCase)
Next x
Print #trz, Mid(strCSV, Len(strColumnDelimiter) + 1)
.MoveNext
Loop
End With
Close #trz
End Function
Thank You