Category: Databases/Data Access/DAO/ADO
Compatability: Visual Basic 3.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (10 Votes)
This code snippet will show you how you can convert an ADO recordset to a delimited
text file in just a couple lines of code using the ADO GetString Method. You can easily export a recordset to a csv file using this method.
Dim rs As New ADODB.Recordset
Dim fName As String, fNum As Integer
rs.Open "Select * from myTable", db, adOpenKeyset,
adLockReadOnly
fName = "C:\MyTestFile.csv"
fNum = FreeFile
Open fName For Output As fNum
Do Until rs.EOF = True
Print #fNum, rs.GetString(adClipString, 1,
",", vbCr)
Loop
rsA.Close
Close #fNum
______________________________________________________________________
GetString Method
Returns the Recordset as a string.
Syntax
Variant = recordset.GetString(class="synParam" onclick="showTip(this)" href>StringFormat, onclick="showTip(this)" href>NumRows, ColumnDelimiter, class="synParam" onclick="showTip(this)" href>RowDelimiter, onclick="showTip(this)" href>NullExpr)
style="VISIBILITY: hidden; OVERFLOW: visible; POSITION: absolute">
Returns the Recordset as a string-valued Variant (BSTR).
Row data, but no schema data, is saved to the string. Therefore, a Recordset
cannot be reopened using this string.
This method is equivalent to the RDO GetClipString method.