Results 1 to 2 of 2
  1. #1
    Mel_3 is offline Novice
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    7

    How to export/save a Query or Report as Text File?

    With Access 2007 on PC XP Pro.



    We need to run a query and then create a custom text file with the results.

    We also want Access to add certain text to the text file before each data field or each new line of data.

    Our thoughts were to run the query and report...
    ...and put the custom text into the report as custom field names or whatever.

    The question:

    1 - Is this the correct approach?
    2 - If not how? (example/sample/tutorial if you can
    3 - Can you "save" a report as a text file?

    Thanks for any help.

  2. #2
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    The question:

    1 - Is this the correct approach?

    2 - If not how? (example/sample/tutorial if you can
    3 - Can you "save" a report as a text file?

    Thanks for any help.
    1) Hard to say.. haven't seen an example of what you want the text file to look like.

    2)
    I create text files and write to them - I add a header, then create text strings and write them to the text files. My text files are errors and info about what has changed. Here is an example....

    Code:
        Dim EF As Integer  'errors file
    
    
        EF = FreeFile
        str = DLookup("LastFileImported", "tblImportFileName")
        pos_slash = InStrRev(str, "\")
        pos_dot = InStrRev(str, ".")
        FileToWrite = Mid(str, pos_slash + 1, pos_dot - pos_slash)
        FileToWrite = CurrentProject.Path & "\ERRORS_" & FileToWrite & "_ImportEmp" & ".txt"
    
        Open FileToWrite For Output As #EF
        'print header text
        Print #EF, "EmpID, SSN, LName, FName, Old Fringe Rate, New Fringe Rate, Change Date"
    
    
        'static text
        Print #EF, "ERROR- Invalid SSN "
        ' error data
        Print #EF, vEID & ", " & vSSN & ", " & vLast & ", " & vFirst
        ' print blank line
        Print #EF,
    
    
        ' close and save text file
        Close #EF



    3) You can (in A2K3) open the report, then export the report as a txt/csv/tab/asc file. (FILE/ EXPORT)


Please reply to this thread with any new information or opinions.

Similar Threads

  1. Export to Text File Using DoCmd Access 2007
    By tonere in forum Programming
    Replies: 1
    Last Post: 03-30-2011, 06:14 PM
  2. export query to fixed width text
    By eladz949 in forum Import/Export Data
    Replies: 1
    Last Post: 02-08-2011, 07:28 AM
  3. export query to fixed width text
    By eladz949 in forum Import/Export Data
    Replies: 5
    Last Post: 01-01-2011, 03:28 PM
  4. Print,save as and export option in report?
    By sunny in forum Reports
    Replies: 1
    Last Post: 07-27-2010, 09:55 AM
  5. Export a simple query result to an excel file
    By wop_nuno in forum Import/Export Data
    Replies: 1
    Last Post: 05-21-2009, 04:18 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums