PDA

View Full Version : Exporting to a text file from Access


phdmom
07-31-2002, 04:21 PM
OK, here's another easy one...

I want to export an Access table to a fixed length text file, and I want the numbers to be right-justified within the space alloted for that field. My field types are Number and either Long Integer or Double.

Ideas? :-?

Gates Is Antichrist
07-31-2002, 06:20 PM
Someone help me out - I can't recall the function that gives blanks or spaces (works like: you say SPACES(4), and it gives " "). I'll call it SPACES for now (which is wrong) until <The Artist Formerly Known As Cho Da> or someone rescues this with the actual name.

You may want to go through Excel for this also. At any rate, the idea is to go
SPACES(8-LEN(FOO)) & FOO
or in Excel (which I nearly always travel through with Access output)
=SPACES(8-LEN(E2))& E2
for a 8-wide field. (Of course adjust for other widths. If you have a double wide, then move to Arkansas, marry a president and join Congress.)

If the field can possibly exceed the width of 8, use e.g. Right(E2,8) instead of E2.

There are other approaches if that one doesn't fuzzy you up.

Oh, a collateral thought off the top of my head, probably not useful for your current need: when I want 2-digit dates to have leading zeroes, I use Right(100+iYear,2). When you want or don't mind leading zeros, do that.

GadgetGeek
08-01-2002, 09:03 AM
Another option, if you don't mind zero filled numbers is to use the format statement. For example, if you need a number to fill 8 places including 2 decimal places, use FORMAT(FOO,"00000.00"). This would print 123.45 as 00123.45. If you don't want leading zeros,

DIM strFoo as String*8
rset strFoo = Format(FOO,"0.00")
print #1, strFoo

Gates Is Antichrist
08-01-2002, 11:46 AM
BTW, FWIW, this board chops extra spaces, so when I posted a double-quote, 8 spaces, and a double-quote, only 1 space showed.

In Access the function I groped for above was SPACE$(8).

For Excel it's REPT(" ",8).