Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Export Access Query (or report) to text files

Posted on 2011-10-17
Medium Priority
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 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 36982727
<...run 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

danishani earned 2000 total points
ID: 36982930
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


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
Implementing simple internal controls in the Microsoft Access application.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

564 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