R
RB Smissaert
Not really an Access question, but I reckon somebody here will know.
As I can now (thanks to Dirk Goldgar) put data directly from Interbase into
an Access table,
without using a RecordSet, I wonder if the same can be done, but now putting
the data in a
text file. I would guess it can be done, but haven't found the right syntax
yet, although I can
do it from text file to text file.
I take it that there will be some performance gain compared to doing:
Data to RecordSet,
RecordSet.GetString
Writing the string to the text file
Although even this is pretty fast:
Sub RecordSetStringToText(rs As ADODB.Recordset, _
strFile As String, _
Optional strColDelim As String = ",", _
Optional strRowDelim As String = vbCrLf, _
Optional lRows As Long = -1, _
Optional strFields As String = "", _
Optional bFieldsFromRS As Boolean)
Dim arr
Dim i As Long
If bFieldsFromRS Then
'get field row from the recordset
'--------------------------------
arr = fieldArrayFromRS(rs)
strFields = arr(0)
If UBound(arr) > 0 Then
For i = 1 To UBound(arr)
strFields = strFields & "," & arr(i)
Next
End If
strFields = strFields & vbCrLf
End If
If lRows = -1 Then
StringToTextFile strFile, _
strFields & _
rs.GetString(2, , strColDelim, strRowDelim)
Else
StringToTextFile strFile, _
strFields & _
rs.GetString(2, lRows, strColDelim, strRowDelim)
End If
'needed as GetString will move the cursor to the end
'---------------------------------------------------
rs.MoveFirst
End Sub
Function fieldArrayFromRS(rs As ADODB.Recordset) As Variant
'gets the field names from an ADO recordset
'and puts them in a one dimensional 0-based array
'------------------------------------------------
Dim objField As ADODB.Field
Dim tempArray()
Dim n As Byte
ReDim tempArray(0 To rs.Fields.count - 1)
For Each objField In rs.Fields
tempArray(n) = objField.Name
n = n + 1
Next
fieldArrayFromRS = tempArray
End Function
Thanks for any advice.
RBS
As I can now (thanks to Dirk Goldgar) put data directly from Interbase into
an Access table,
without using a RecordSet, I wonder if the same can be done, but now putting
the data in a
text file. I would guess it can be done, but haven't found the right syntax
yet, although I can
do it from text file to text file.
I take it that there will be some performance gain compared to doing:
Data to RecordSet,
RecordSet.GetString
Writing the string to the text file
Although even this is pretty fast:
Sub RecordSetStringToText(rs As ADODB.Recordset, _
strFile As String, _
Optional strColDelim As String = ",", _
Optional strRowDelim As String = vbCrLf, _
Optional lRows As Long = -1, _
Optional strFields As String = "", _
Optional bFieldsFromRS As Boolean)
Dim arr
Dim i As Long
If bFieldsFromRS Then
'get field row from the recordset
'--------------------------------
arr = fieldArrayFromRS(rs)
strFields = arr(0)
If UBound(arr) > 0 Then
For i = 1 To UBound(arr)
strFields = strFields & "," & arr(i)
Next
End If
strFields = strFields & vbCrLf
End If
If lRows = -1 Then
StringToTextFile strFile, _
strFields & _
rs.GetString(2, , strColDelim, strRowDelim)
Else
StringToTextFile strFile, _
strFields & _
rs.GetString(2, lRows, strColDelim, strRowDelim)
End If
'needed as GetString will move the cursor to the end
'---------------------------------------------------
rs.MoveFirst
End Sub
Function fieldArrayFromRS(rs As ADODB.Recordset) As Variant
'gets the field names from an ADO recordset
'and puts them in a one dimensional 0-based array
'------------------------------------------------
Dim objField As ADODB.Field
Dim tempArray()
Dim n As Byte
ReDim tempArray(0 To rs.Fields.count - 1)
For Each objField In rs.Fields
tempArray(n) = objField.Name
n = n + 1
Next
fieldArrayFromRS = tempArray
End Function
Thanks for any advice.
RBS