Exporting recordset to textfile

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lindiecoetzee
    New Member
    • Jul 2008
    • 1

    Exporting recordset to textfile

    Hi

    I have a table with x (not a fixed number) records in it and I need to run a code which can select certain fields for each record in the table and then export these fields for each records into a seperate text file.

    I know that I have to define my table as a recordset, but then it is giving me errors when I am trying to export the recordset with the transfertext function.

    Is it because transfertext does not work for recordsets?
    And would appreciate of someone can give me the entire code for the problem!
    Thanx!
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    1. Create a Query that consists of only the Fields you wish to Export to Text Format from the Table
    2. Assuming I create a Query called qryEmployees, based on tblEmployees, that consists of only selective Fields.
    3. Assuming I wish to Output this Query (acOutputQuery) in Text Format (acFormatTXT) to the C:\TestDir\ Directory and name the File Employee.txt (C:\TestDir\Emp loyee.txt).
    4. Assuming I wish to load the Text File into the Application assigned to this Task (the True Argument).
      Code:
      DoCmd.OutputTo acOutputQuery, "qryEmployees", _
          acFormatTXT, "C:\TestDir\Employee.txt", True
    5. Let me know how you make out.

    Comment

    Working...