Export Text File consisting header and table

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I need to export to an ASCII file the following.
Frist line is a header record such as "this is the header".
The second line then contains the rows of a data table in a specific set
number of characters with a filler at the end to make a full 80 character
record.

Can someone provide a simple example of this? Also, what is a good MS
Access 2003 book that covers things such as this?

Thanks
 
Frist line is a header record such as "this is the header".
The second line then contains the rows of a data table in a specific
set number of characters with a filler at the end to make a full 80
character record.

It's not very hard:

open FileName for output as #OutFileH

print #outfile, "This is the header"

do while not rst.EOF
print #outfile, padright(rst!First, 18));
print #outfile, padright(rst!Second, 12));
print #outfile, padright(rst!Third, 9));
' finished row
print #outfile

rst.movenext
loop

close #outfile
rst.Close


Oh yes, you'll need something like this too:

public function padright(Something as variant, PadWidth as integer) _
as string

dim temp as string

if not isnull(something) then
' standard right-padding algorithm
' use default data type conversion: should really be a lot
' more defensive e.g. with decimal points, date formats,
' booleans etc etc etc.
temp = Right(space(padwidth) & CStr(Something), PadWidth)

else
temp = Str(padwidth,"*")

end if
padright = temp
end function

Hope that helps
 
Back
Top