Link to home
Start Free TrialLog in
Avatar of jasonck74
jasonck74

asked on

Exporting to fixed width text file

I created a macro that exports data from my table to fixed width text file.  The action argument requires a specification name.  How do I tell it to place the columns in a specific position?
Avatar of nexusnation
nexusnation
Flag of United States of America image

show's how much you know about text files. there are no columns in A TEXT FILE. however, you can export it to word.
Avatar of pbleighton
pbleighton

nexusnation is technically correct, but you can make each of the fields in a text fiel always appear in the same place (i.e. the sixth through tenth characters of the string comprising the line). I think this may be what you mean. If it is:

You can use VBA to create a text file, then populate it row by row with your data.  When a record is not the maximum length allowed/required for a column, use something like:
Format(Left(Trim(Str(rs!FieldName)), 5), "@@@@@")
for a field you want to display in 5 character format,where rs is the recordset you are using.
This isn't trivial, but it can be done, and is tedious, but straightforward.
that would be very, very tedious.
ASKER CERTIFIED SOLUTION
Avatar of nico5038
nico5038
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jasonck74

ASKER

Actually, someone else on my team told me about the advanced button on the export function.  I was able to save the specifications & use it in my macro.  Do you know how I can go about insert a header & trailer record into my text file?  Header would look like thise "Header 20449" and Trailer like "Trailer204492003-02-25".
i don't know, but nico will if it can be done.

if you go and ask a question about it, i will give you this word of advise. it is called a "footer", not a "trailer" :-)
If the first field is long enough to hold the needed:
"Trailer204492003-02-25"

Then this will do:
select "Header 204492" as field1, "" as field2, "" as field3, etc
UNION
select field1, field2, field3, etc
UNION
select "Trailer204492003-02-25" as field1, "" as field2, "" as field3, etc

The date of the trailer can ofcourse be appended using the Date() function.

When you have multiple shorter field, then the "Header 204492" as field1 must be splitter to fit those fields like:
select "Heade" As field1, "r 204492" as field2, etc

Idea ?

Nic;o)
i knew that you would know...