Results 1 to 4 of 4
  1. #1
    craig1988 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Aug 2014
    Posts
    82

    Fixed width txt file with dynamic header and footer

    Hi all

    I found a link that has done what I needed to get done.



    http://www.access-programmers.co.uk/...d.php?t=168031

    One last problem, that Im sure is fixable is that I need to pad out certain columns with trailing spaces. See below.

    What I am currently getting.
    30151942788001 010011100 BLUESTONE SALES &DISTRIBUTION LTD.26 OAKTREE BUSINESS PARK
    30151971666001 010011100 GmchequesUNIT 1 & 2
    30151919069001 010011100 MR. BRIAN MURRAY M.D.23A MOYLE ROAD

    What I need to get
    30151942788001 010011100 BLUESTONE SALES &DISTRIBUTION 26 OAKTREE BUSINESS PARK
    30151971666001 010011100 Gmcheques UNIT 1 & 2
    30151919069001 010011100 MR. BRIAN MURRAY M.D. 23A MOYLE ROAD

    The print method I am using appears to print to txt file in a delimited style which I dont want.

    Any help would be greatly appreciated

    Here is the code I have so far...

    Code:
    Private Sub btnRunOrders_Click()
        Dim StrFileName, StrPath As String
        
        StrFileName = "Bray.txt"
        
        StrPath = "U:\"
        
        Open StrPath & StrFileName For Output As #1
        
        Print #1, "This is a dynamic header" & "9999999"
        
        Dim Rs As DAO.Recordset
        Set Rs = CurrentDb.OpenRecordset("tblBrayOrder")
            Do Until Rs.EOF
            Print #1, Rs("SortCode") & Rs("AccNo") & Rs("Static1") & Rs("Static2") & Rs("Static3") & Rs("Style") & Rs("Static2") & Rs("Space1") & Rs("Address1") & Rs("Address2")
            Rs.MoveNext
            Loop
            Close #1
            Rs.Close
            Set Rs = Nothing
    End Sub

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    What you're showing is not fixed width, fixed width means all columns use the same number of spaces so the next column always starts on the same column.

    i.e.:
    Code:
    30151942788001  010011100  BLUESTONE SALES &DISTRIBUTION         26 OAKTREE BUSINESS PARK
    30151971666001  010011100  Gmcheques                             UNIT 1 & 2
    30151919069001  010011100  MR. BRIAN MURRAY M.D.                 23A MOYLE ROAD
    If this is what you actually want you will want to define the column width for each field then pad it with spaces:

    Code:
    Private Sub btnRunOrders_Click()
        Dim StrFileName, StrPath As String
        
        StrFileName = "Bray.txt"
        
        StrPath = "U:\"
        
        Open StrPath & StrFileName For Output As #1
        
        Print #1, "This is a dynamic header" & "9999999"
        
        Dim Rs As DAO.Recordset
        Set Rs = CurrentDb.OpenRecordset("tblBrayOrder")
            Do Until Rs.EOF
            Print #1, left(Rs("SortCode") & string(16, " "), 16) & left(Rs("AccNo") & string(11, " "), 11) & left(Rs("Static1")  & string(32, " "), 32) >>>----> and so on
            Rs.MoveNext
            Loop
            Close #1
            Rs.Close
            Set Rs = Nothing
    End Sub

  3. #3
    craig1988 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Aug 2014
    Posts
    82
    Hi rpeare

    Kudos on solving my problem despite my incorrect description of my problem!! That is exactly what I needed. I have one more issue before I can put this into action.

    I have two fields in the above that are serial numbers. I have them formatted as "000000" in their table to give the serial number its leading zeros. When I use the print method it does not seem to take that formatting with it. I presume I have to format them through VB. I am unsure how to do this. Any ideas??

    Thanks for your help to date!!

  4. #4
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    use the format command in your code as well

    ... & left(format(Rs("SerialNumber"), "000000") & string(11, " "), 11) & ....

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

Similar Threads

  1. Export Fixed Width txt File with dynamic header and footer
    By craig1988 in forum Import/Export Data
    Replies: 2
    Last Post: 12-18-2014, 03:40 AM
  2. Replies: 2
    Last Post: 10-15-2014, 02:23 AM
  3. Replies: 5
    Last Post: 02-20-2011, 08:22 PM
  4. Replies: 5
    Last Post: 09-16-2009, 01:56 AM
  5. Formatting Fields and Fixed Width Exporting
    By Panman01 in forum Access
    Replies: 1
    Last Post: 05-22-2009, 09:32 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