TXT Tab Delimited

bhelmy

Registered User.
Local time
Tomorrow, 01:49
Joined
Dec 6, 2015
Messages
62
need I help
when this issue solve I will finish my project .

NEED CODE

1-
I have a ( Query1 ) I need to export it as a txt file tab delimited with a header of Query .
2- I have a ( Query2 ) I need to export it as a txt file tab delimited with a header of Query and space row before header .

thx
 

Attachments

  • 1.txt
    1.txt
    610 bytes · Views: 92
  • 2.txt
    2.txt
    612 bytes · Views: 85
1. You can simply use the Docmd.Transfertext to create it
2. See 1, but you need some vba to make the blank line or a "smart" union query to insert the blank line.
 
Code:
Option Compare Database
Option Explicit
'*********************
'* arnelgp
'*
'* parameters:
'*
'* strTable             table/query name or select statement
'* strOutput            path and filename to which it will saved (like: z:\test.txt)
'*                          if not supplied, file will be saved on same folder as the
'*                          db (text.txt)
'* strDelimiter         delimiter to use for export
'* bolExtraSpaceAbove   if you need extra space above your header, just passed True
'*

Public Sub DataToText(ByVal strTable As String, Optional ByVal strOutput As String = "", _
                            Optional ByVal strDelimiter As String = "", _
                            Optional ByVal bolExtaSpaceAbove As Boolean = False)
    
    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    Dim outFile As Integer
    Dim i As Integer
    Dim LineOfText As String
    
    If strOutput = "" Then strOutput = CurrentProject.Path & "\Text.txt"
    If strDelimiter = "" Then strDelimiter = Chr(9)
    If Dir(strOutput) <> "" Then Kill (strOutput)
    outFile = FreeFile
    Open strOutput For Output As #outFile
    Set db = CurrentDb
    Set rs = CurrentDb.OpenRecordset(strTable, dbOpenSnapshot)
    
    
    With rs
        If Not (.BOF And .EOF) Then
            .MoveFirst
            If bolExtaSpaceAbove Then
                Print #outFile, ""
            End If
            'if you want column headers, uncomment the following 5 lines of code
            For i = 0 To .Fields.Count - 1
                LineOfText = LineOfText & .Fields(i).Name & strDelimiter
            Next i
            LineOfText = Left(LineOfText, InStrRev(LineOfText, strDelimiter) - 1)
            Print #outFile, LineOfText

            'loop through records
            Do While Not .EOF
                LineOfText = ""
                'build up line of text
                For i = 0 To .Fields.Count - 1
                    LineOfText = LineOfText & Nz(.Fields(i)) & strDelimiter
                Next i
                LineOfText = Left(LineOfText, InStrRev(LineOfText, strDelimiter) - 1)
                'write line of text to file
                Print #outFile, LineOfText
            .MoveNext
            Loop
        End If
    End With
    
    Close #outFile
    rs.Close
    Set rs = Nothing
    Set db = Nothing
    
End Sub
 
sorry
i am new vb devloper can you please put this code in a sampel witch attached
i form need buttom to export to C:\

PLEASE
 

Attachments

it is better to save the text file to MyDocuments. saving to C:\ in some system, requires that you have all privelege in that drive.
 

Attachments

thx sooooo mush
but one error more 3061 : too few parameters Expected 1
i have parameters in Qery


thx thx 4 every things
 

Attachments

Is this exported txt file going to be used to populate a pdf?
 
i can't understand .... but this error when export the txt file
but solved when changing parameter as fixed one not depend on parameter in form
 
many thx
i finished my project --- u help me ....
 

Users who are viewing this thread

Back
Top Bottom