Solved

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

Posted on 2008-06-19
5
1,054 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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

This is an explanation of a simple data model to help parse a JSON feed
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

831 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