Export Access Query (or report) to text files

Posted on 2011-10-17
Last Modified: 2012-06-27
I have a list of codes that I need to create a text file for each code in my query. I am able to see what I want in my query and even export it with a single code in the queyr but I am wanting to automate the process to run off a list of all the codes(via table or query) in an automated fashion. I have Access 2003 now but I am getting Access 2010 soon so I dont know if the new version has something that I can use for this.

I need help in figuring out what way would be the best.
Question by:wilpitz
    LVL 119

    Expert Comment

    by:Rey Obrero
    < off a list of all the codes>

    what list of codes are you referring to?

    to  use automation to export queries/table to a text file, you will need export specification..

    see this link

    after creating the export specification, you can use this command to export the queries or tables

    DoCmd.TransferText acExportDelim, "ExportSpecName", "TableNameOrQueryName", "C:\myText.txt", True

    <I have Access 2003 now but I am getting Access 2010 soon so I dont know if the new version has something that I can use for this. >

    yes, you can still use the export specification that you created in A2003.
    LVL 12

    Accepted Solution

    If you want to export each 'unique' code to be exported as a seperate TXT file, then you can do something like this:

    Dim rst As DAO.Recordset
    Dim x As String
      Set rst = CurrentDb.OpenRecordset("SELECT * FROM tblYourTableName")

        Do Until rst.EOF
            x = FreeFile
            Open "c:\YourPathName\" & rst!Code & ".txt" For Append As x
            Print #x, rst!Code, rst!CodeName, rst!MoreFields  ' can add more fields here
            Close #x
        Set rst = Nothing

    Another approach you can find in here:

    Hope this is what you are after,

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    The first two articles in this short series — Using a Criteria Form to Filter Records ( and Building a Custom Filter ( — discuss in some detail how a form can be…
    Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
    In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
    In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

    754 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

    21 Experts available now in Live!

    Get 1:1 Help Now