arnelgp
..forever waiting... waiting for jellybean!
- Local time
- Tomorrow, 04:54
- Joined
- May 7, 2009
- Messages
- 20,641
can you try manual export using VBA:
Code:
'=============================================
' Export Table or Query to CSV using raw file I/O
'=============================================
Public Sub ExportToCSVRaw(ByVal SourceName As String, Optional ByVal OutputPath As String = "")
' SourceName: the name of table/query to export
' OutputPath: the path + filename to export to
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim f As Integer
Dim i As Integer
Dim lineOut As String
Set db = CurrentDb
Set rs = db.OpenRecordset(SourceName, dbOpenSnapshot)
If rs.EOF Then
MsgBox "No records found in " & SourceName, vbInformation
rs.Close
Exit Sub
End If
' if no OutputPath is passed, we save it
' to MyDocument with same name as the SourceName (.csv)
If Len(OutputPath) = 0 Then
OutputPath = Environ$("Userprofile") & "\Documents\" & SourceName & ".csv"
End If
' Open file for writing
f = FreeFile
Open OutputPath For Output As #f
'--- Write header line ---
For i = 0 To rs.Fields.Count - 1
lineOut = lineOut & QuoteCSV(rs.Fields(i).Name)
If i < rs.Fields.Count - 1 Then lineOut = lineOut & ","
Next i
Print #f, lineOut
'--- Write data lines ---
Do While Not rs.EOF
lineOut = ""
For i = 0 To rs.Fields.Count - 1
lineOut = lineOut & QuoteCSV(Nz(rs.Fields(i).Value, ""))
If i < rs.Fields.Count - 1 Then lineOut = lineOut & ","
Next i
Print #f, lineOut
rs.MoveNext
Loop
'--- Clean up ---
Close #f
rs.Close
Set rs = Nothing
Set db = Nothing
MsgBox "Export complete: " & OutputPath, vbInformation
End Sub
'=============================================
' Helper: Quote and escape text for CSV
'=============================================
Private Function QuoteCSV(ByVal txt As String) As String
Dim s As String
s = CStr(txt)
s = Replace(s, """", """""") ' Escape quotes
QuoteCSV = """" & s & """"
End Function