
Along the same lines as my posts on exporting a SalesLogix DataGrid (well, exporting the Recordset behind the grid) to Excel, Michael Cessna from SalesLogix shared this quick bit of code for dumping a Recordset to a CSV file (posted in the SalesLogix Business Partner newsgroups)
Option Explicit Const adClipString = 2 ' ExportRecordsetToCSV objRS, "C:Test.csv", True, True Sub ExportRecordsetToCSV(Recordset, FileName, IncludeFieldNames, MoveFirst) Dim objFSO Dim objFile Dim iFieldCount Dim oFields() Dim strHeader Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.CreateTextFile(FileName, True) If MoveFirst Then Recordset.MoveFirst End If If IncludeFieldNames Then Redim oFields(Recordset.Fields.Count) For iFieldCount = 0 To Recordset.Fields.Count -1 oFields(iFieldCount) = Recordset.Fields(iFieldCount).Name Next strHeader = Join(oFields, Chr(9)) objFile.WriteLine(strHeader) End If objFile.Write(Recordset.GetString(adClipString)) objFile.Close() Set objFile = Nothing Set objFSO = Nothing If MoveFirst Then Recordset.MoveFirst End If End Sub
Doh! I knew that. I guess my mind just gets tripped up moving back and forth between legecy and VB Script..