Solved

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

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

Expert Comment

by:Rey Obrero
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

863 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

25 Experts available now in Live!

Get 1:1 Help Now