Solved

Access 2003: Append table data to a text file with code - VBA

Posted on 2008-06-19
5
1,055 Views
Last Modified: 2013-11-27
I need to append data from a table to a text file that has already been created with a DoCmd method.  Here is that
DoCmd.TransferText acExportFixed, "EXPORT_TABLE_Export_Specification", "EXPORT_TABLE", "C:IA_Subscriptions\Test.txt"

It works fine but now I want another line that appends data from another table to the text file.  Any help is greatly appreciated.

John
0
Comment
Question by:JohnMac328
  • 3
5 Comments
 
LVL 65

Expert Comment

by:rockiroads
ID: 21823644
one of two ways perhaps?

1. Output to temp file, then append contents of temp file to main file

2. Open file, and write to it


one sec...
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 21823674
create a union query

select * from EXPORT_TABLE
union all
select * from OTHERTable

saved the union query then use in the


DoCmd.TransferText acExportFixed, "EXPORT_TABLE_Export_Specification", "UnionQueryName", "C:IA_Subscriptions\Test.txt"
0
 
LVL 65

Accepted Solution

by:
rockiroads earned 500 total points
ID: 21823734
Method 1

Public Sub RunReport()

    Dim tempFile As Integer
    Dim mainFile As Integer
    Dim sLine As String
    Dim sTempFile As String
    Dim sMainFile As String
   
    sTempFile = "c:IA_Subscriptions\fred.txt"
    sMainFile = "C:IA_Subscriptions\Test.txt"
   
    DoCmd.TransferText acExportFixed, "EXPORT_TABLE_Export_Specification", "EXPORT_TABLE", sTempFile
   
    tempFile = FreeFile
    Open sTempFile For Input As #tempFile
   
    mainFile = FreeFile
    Open sMainFile For Append As #mainFile
   
    While Not EOF(tempFile)
        Line Input #tempFile, sLine
        Print #mainFile, sLine
    Wend
   
    Close #tempFile
    Close #mainFile
End Sub

0
 

Author Closing Comment

by:JohnMac328
ID: 31468856
Great, just what I needed.

Thanks
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 21823879
Cool :)
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question