Link to home
Start Free TrialLog in
Avatar of Pdeters
Pdeters

asked on

Export Access table to csv file

I am exporting an Access table to a csv file.
The problem I am having is that one of the fields which is defined as text has numbers in like
009900
it is exporting like 9900
I need it to be 00900

this is what I am using to exp0rt

 DoCmd.TransferText acExportDelim, "spec", "ExportTable", stOutputName & ".csv", False
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

create a query against ExportTable (select all fields) and specify that field as text with  cstr([nameoffield])  save the query and use it for export instead of the table.
Avatar of Pdeters
Pdeters

ASKER

not all fields have a value - having a problem with the null fields exporting
Avatar of Pdeters

ASKER

I receive an error
use the nz() function

nz([fldName],"")  '< for text data
nz([fldname],0)   ' < for number

to use the cstr()

        cstr(nz([fldName],""))
Avatar of Pdeters

ASKER

Still not getting the leading 00 on the text fields - it is dropping them
can you upload your db?
Avatar of Pdeters

ASKER

I will need to take some stuff out
before you do, have you tried exporting using fixed width?
Avatar of Pdeters

ASKER

I am using the button on the form
Avatar of Pdeters

ASKER

Using Button on Main Form
db1.mdb
Avatar of Pdeters

ASKER

yes I am exporting with fixed width in the specs
Avatar of Pdeters

ASKER

I need export in fixed widths
ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America 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 Pdeters

ASKER

I need to have it be able to open up in Excel in separate columns - it has to have the extention .csv
Avatar of Pdeters

ASKER

when I do the acExportFixed it goes into one field/column in Excel
Avatar of Pdeters

ASKER

Is this possible?
must it be a .csv file?
Pdeters,

First things first.
The Output file: c:\ExportFile.csv *DOES* have the leading zeros.

If you open the file with *NotePad*, you will clearly see the leading zeros.

If you open the CSV file with *Excel*, Excel will convert these values to numbers.

So the ultimate question is what application will these CSV files end up going to?
If Excel, then why not export to the Excel format?

If they are going to some other program, you have to test the file in this application to see if they will be *USED* in this program correctly as Text (with the Leading zeros)

You cannot tell anything form "Opening/viewing" the file, because any program to view the file may have it's own filters. (like Excel)

You have to actually test the file in its target application and veiw the output to be sure.

JeffCoachman
untitled.JPG
Avatar of Pdeters

ASKER

Yes - If I open with note pad the leading 0 are there but I gues I am not being clear.
the leading 0 need to be there in Excel but the file extension needs to be csv.
a work around

use this in the query

select IIf(Left([FieldI],1)="0",Chr(39) & [FieldI],[FieldI])
from tableX
SOLUTION
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