how do i tabulate a list into 2 columns in a text file?

Wozzzzza

Registered User.
Local time
Today, 04:27
Joined
Feb 3, 2007
Messages
27
I have a table full of data i need to extract and place into a text file. I can do this no worries, but what else is required is to place the extracted data into 2 columns in the text file, this is what i cant work out how to do.

here is what i have below
Code:
Sub CreateBulletinList()
 
    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    Dim fso As Object
    Dim ts As Object
    Set db = CurrentDb
 
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set ts = fso.CreateTextFile("c:\List.txt", True)
    Set rs = db.OpenRecordset("qryBulletinList")
    If rs.RecordCount = 0 Then
        MsgBox "There is no data at this current time", vbExclamation, "No Records"
        Set db = Nothing
        Exit Sub
    End If
    With rs
    'writes a heading in the text file        
    ts.WriteLine DLookup("strText", "tblStrings", "strChecked = TRUE and strGroup = 'YES'")
        ts.WriteLine
        .MoveFirst
        Do While Not .EOF
            ts.WriteLine ![dATa]
 
        .MoveNext
        Loop
    End With
 
    Set rs = Nothing
    ts.Close
    Set ts = Nothing
    Set fso = Nothing
End Sub

output is like

Code:
Heading goes here
 
list itemmm 1
list itemmmmmm 2
list item 3
list item 4
list item 5
list item 6

i want it to be like this but cant work it out how the list items are varying lengths form about 10 characters to 40 characters and the 2 columns need to be all neatly under each other at the start of each item in both columns like below.
Code:
Heading goes here
 
list itemmm 1      list item 4
list itemmmmmm 2   list item 5
list item 3        list item 6

anyone help me out here??
 
One way is to use a linked file. Records can be appended to a a linked text file.
The new records will be written using the same line construction as the import specification.

Otherwise pad the values for the left column to a specified width by adding spaces.
Use the Len funtion to read the original value length and concatenate spaces as required using a loop counted to the difference between the original and required length.
 
Otherwise pad the values for the left column to a specified width by adding spaces.
Use the Len funtion to read the original value length and concatenate spaces as required using a loop counted to the difference between the original and required length.
yep, did it that way, ran through the records to find longest then padded the rest to that length plus 1 then appended on end of it using array then wrote to text file.
worked perfect, thanks.
 

Users who are viewing this thread

Back
Top Bottom