Solved

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

Posted on 2008-06-19
5
1,041 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
Comment Utility
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 119

Expert Comment

by:Rey Obrero
Comment Utility
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
Comment Utility
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
Comment Utility
Great, just what I needed.

Thanks
0
 
LVL 65

Expert Comment

by:rockiroads
Comment Utility
Cool :)
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
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 …

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now