Results 1 to 5 of 5
  1. #1
    atai is offline Novice
    Windows 10 Access 2016
    Join Date
    Nov 2019
    Posts
    22

    how to aggregate 3 txt files

    Hello,

    I have a problem on my Access VBA program.
    I have a function that create a txt file that need to be imported in a different system
    My VBA code use 3 differents Access tables with different structure.


    One for the header, one for the rows and one for the footer.
    these 3 different tables are then exported on 3 txt files.
    No problem until this, but when I try to aggregate these 3 files I have a problem.
    I use a batch file that copy the 3 files in one but at the end of the file created there is a strange character created that create an error when I run the import program that load the file created.
    Do you know other way to aggregate more files txt in one maybe using VBA?
    Many thanks

  2. #2
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    It might help to see your code. Is there a reason you don't just create a single file from the function? Perhaps a UNION query is another alternative, joining the header, detail, and footer?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    orange's Avatar
    orange is online now Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,725
    Please tell us more about your use of "aggregate".

    Is it A.txt + B.txt + C.txt ==>Final.txt?

    Perhaps you could provide a sample (mock up) that shows the issue.

  4. #4
    atai is offline Novice
    Windows 10 Access 2016
    Join Date
    Nov 2019
    Posts
    22
    This is the batch file
    cd\venistar\v9_std_imp\pre-txt-in
    copy *.txt c:\venistar\v9_std_imp\txt-in\po.txt

    it's very simple, it copy all the folder pre-txt-in on the file po.txt
    I run it with shell comand on my VBA

    and this is the result
    H;14;002680pre;002680;001;001;0;001;;11112019;;;14
    I;14;8719852222981;1; 10.8;;
    I;14;8719852222929;2; 10.8;;
    I;14;8719852222752;2; 10.8;;
    I;14;8719852222394;1; 10.8;;
    S;14;pre nov-dic + coll feb-mar;10%;Ri.Ba. 60/90/120 gg f.m. dec;;;

    May I use union query even if the 3 tables have different number of fields?

    P.S.: after sent the post I realize that the strange character is a a carriage return

  5. #5
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I meant the code that creates the text files. Yes, you can use a UNION query, you just have to add placeholders for fields that don't exist, like this where Table2 doesn't have Field2:

    SELECT Field1, Field2, Field3
    FROM Table1
    UNION ALL
    SELECT Field1, Null, Field3
    FROM Table2

    You could anything there, not just Null: 0, "", "N/A", etc.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 1
    Last Post: 04-10-2019, 11:39 AM
  2. Replies: 4
    Last Post: 07-21-2017, 01:07 PM
  3. Replies: 2
    Last Post: 10-14-2016, 12:27 PM
  4. Replies: 4
    Last Post: 05-15-2014, 12:49 PM
  5. Replies: 1
    Last Post: 02-21-2011, 09:55 PM

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