Heenan, Lambert
Lambert.Heenan at chartisinsurance.com
Thu Oct 27 15:49:55 CDT 2011
One small bug fix and the addition of the ability to include the field names...
Function ExportTab(RSName As String, FileName As String, Optional boolIncludeFieldNames As Boolean = True) As Boolean
Dim rs As DAO.Recordset
Dim ff As Long
Dim x As Long
Dim strtemp As String
On Error GoTo errtrap
ff = FreeFile
Set rs = CurrentDb.OpenRecordset(RSName)
Open FileName For Output As #ff
If boolIncludeFieldNames Then
For x = 0 To rs.Fields.Count - 1
strtemp = strtemp & rs.Fields(x).Name
If x < rs.Fields.Count - 1 Then
strtemp = strtemp & vbTab
End If
Next x
Print #ff, strtemp
End If
While Not rs.EOF
strtemp = rs(0)
For x = 1 To rs.Fields.Count - 1
strtemp = strtemp & vbTab & rs(x)
Next
strtemp = strtemp ' & vbCrLf = don't need this. Print #ff implies a CRLF at the end
Print #ff, strtemp
rs.MoveNext
Wend
Close #ff
rs.Close
Set rs = Nothing
ExportTab = True
Exit Function
errtrap:
MsgBox "Error: " & Err.Description & " in Function ExportTab()"
End Function
Lambert
-----Original Message-----
From: accessd-bounces at databaseadvisors.com [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Stuart McLachlan
Sent: Thursday, October 27, 2011 4:20 PM
To: Access Developers discussion and problem solving
Subject: Re: [AccessD] Tab delimited text file
And here's a DAO version I've quickly knocked up (not tested):
Function ExportTab(RSName As String, FileName As String) As Boolean Dim rs As DAO.Recordset Dim ff As Long Dim x As Long Dim strtemp As String On Error GoTo errtrap ff = FreeFile Set rs = CurrentDb.OpenRecordset(RSName) Open FileName For Output As #ff While Not rs.EOF
strtemp = rs(0)
For x = 1 To rs.Fields.Count - 1
strtemp = strTemp & vbTab & rs(x)
Next
strtemp = strtemp & vbCrLf
Print #ff, strtemp
rs.MoveNext
Wend
Close #ff
rs.Close
Set rs = Nothing
ExportTab = True
Exit Function
errtrap:
MsgBox "Error: " & Err.Description & " in Function ExportTab()"
End Function
On 27 Oct 2011 at 15:06, Paul Hartland wrote:
> Here is a little function I have quickly knocked together, can't find
> my source, but no reason why it shouldn't work, you pass a recordset
> to function to export, could also pass the export path name as well if
> you wanted:
--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com