Results 1 to 8 of 8
  1. #1
    JoRo50 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2014
    Posts
    4

    Cool Export from access to multiline text file

    An outside agency is requiring me to report data for each instance of my dataset on multiple lines. Right now I can export the data in this form:

    1-V1, 1-V2, 1-V3, 1-V4, 1-V5, 1-V6, 1-V7, 1-V8, 1-V9
    2-V1, 2-V2, 2-V3, 2-V4, 2-V5, 2-V6, 2-V7, 2-V8, 2-V9

    where 1-V1 means first instance, variable 1. I need to put the information into a text or CSV file in the form

    1-V1, 1-V2, 1-V3
    1-V4, 1-V5
    1-V6, 1-V7, 1-V8, 1-V9
    2-V1, 2-V2, 2-V3
    2-V4, 2-V5
    2-V6, 2-V7, 2-V8, 2-V9.

    Right now the query reads:
    SELECT V1, V2, V3, V4...V9
    FROM Table
    GROUP BY V1, V2, V3, V4...V9.

    Is there a way to do this in Access? Thanks for your help.



    I'm using a windows 7 version of Access 2010. Both are 32bit.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    What is the line break, 4 columns? 3 columns?
    1-V1 you have 3 columns
    but 1-V6 has 4 columns on the line.

    How many columns do you want?

  3. #3
    JoRo50 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2014
    Posts
    4
    Ranman, the number of columns and the field length for each column is unique for each line. (this wasn't my idea). I'm trying to avoid creating the text file and then manually entering the line breaks.

  4. #4
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    The only way I can think of is to use VBA to read the query and write to a text/CSV file.
    You (the code) control which variables are written and when the line breaks.

    Is there always 9 variables?

    Not hard, just lots of code.

  5. #5
    JoRo50 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2014
    Posts
    4
    There are actually about 45 variables broken into 8 lines. The number of variables and the number of lines are the same for each instance. I just used these 9 as an example to show that the number of variables per line are not the same.
    Would I be able to do the VBA coding in access or do I have to use a different mechanism. I'm open to any options here.

  6. #6
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Yes, the VBA is in Access.

    In code, you would need to:

    Create the text/CVS file
    Write the header if required
    Open the query as a recordset
    Determine if there are records
    Begin a loop
    Read the first line
    Parse the line (could be an array or into variables
    Create the string to write
    Write the output string
    Loop
    Clean up (close the text file, recordsets, etc)

    I always have a message box saying "Done" and possible where the file was saved, number of lines read/written, etc.

  7. #7
    JoRo50 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2014
    Posts
    4
    Thanks, Steve. I will give this a shot. I've done a little with VBA but not much so I may have more questions later.

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Export Whole table to text file with UTF-8
    By Auto in forum Import/Export Data
    Replies: 3
    Last Post: 08-29-2013, 05:09 PM
  2. Get Export File name from Unbound Text Box
    By FinChase in forum Import/Export Data
    Replies: 1
    Last Post: 01-11-2012, 11:09 AM
  3. trying to export data to a text file
    By itm in forum Access
    Replies: 1
    Last Post: 06-30-2011, 10:40 AM
  4. Replies: 1
    Last Post: 06-09-2011, 11:10 PM
  5. Export to Text File Using DoCmd Access 2007
    By tonere in forum Programming
    Replies: 1
    Last Post: 03-30-2011, 06:14 PM

Tags for this Thread

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