Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Send text file attachment in particular text format?

Status
Not open for further replies.

kculpepper77

Programmer
Mar 21, 2003
15
0
0
US
I need to send an access table as a text file attachment but not in the default access text format; it needs to be a delimited format with separations by "|" and with no text qualifier.

Any ideas on how I could do that?

Thanks much.
 
Paste the following code into a new module:
Code:
Public Function TableToText(tableName As String, textName As String) As Boolean
On Error Resume Next

    Dim rst As Recordset, tbd As TableDef, colCount As Integer
    
    For Each tbd In CurrentDb.TableDefs
        If tbd.Name = tableName Then TableToText = True
    Next
    
    If TableToText = False Then Exit Function
    
    Set rst = CurrentDb.OpenRecordset(tableName, dbOpenDynaset)
    If rst.RecordCount Then
        Kill textName
        Open textName For Output As #1
        For colCount = 0 To rst.Fields.Count - 2
            Print #1, rst.Fields(colCount).Name; "|";
        Next colCount
        Print #1, rst.Fields(rst.Fields.Count - 1).Name
        While Not rst.EOF
            For colCount = 0 To rst.Fields.Count - 2
                Print #1, rst.Fields(colCount).Value; "|";
            Next colCount
            Print #1, rst.Fields(rst.Fields.Count - 1).Value
            rst.MoveNext
        Wend
        Close #1
    End If

End Function

You can call this function thus:
[tt]Call TableToText("Table1","C:\My Documents\Table1.txt")[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top