Discussion Locked

Creating a 0-filled field - Access 97

0 helpful
5 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I have data that needs to be exported to a fixed-length text file. One field (numeric)is required to be 0-filled and right-justified. I have tried setting the field's format to 00000000000.The field appears correctly in Access, but it exports as left-justified and blank-filled.

Is there a way I can change the data in this field to be text, and include the zeros?

Any help would be greatly appreciated.

5 replies

by peyison

Three ideas, one requires writing VBA code, the other two don't. Here are the other two first:

1) Export the table to Excel - make sure the "Save Formatted" option is checked. From Excel, save the file as a CSV file.

2) Change the field to have a datatype of text. Before exporting the data, run an Update query that adds the 0's. Create a new query based on your table. From the main menu, choose Query, Update Query. Select your Field in the first Field list, and in the Update To: cell enter - Format([tblMyTable]![MyField],"00000000000") - replacing the correct table and field name. This will update the contents of the field.

It is okay if you run this on a record more than once, but you might not like the way the field shows up in your interface. Another option is to keep the field Numeric, and create another table that has all the same fields, but the numeric one is Text - then do the same sort of Query (except it will be an Append query) to copy data to the temporary table- then export the temporary table. You'll probably want to delete the data in the temporary table before running the query. This can all be automated in VBA.

3) The third option is to write some VBA code to do the export. You can format the data any way you want it, and since you're using VBA you can automate the whole thing - just press a button, enter a name if you want, and it will do the rest. If you want some more ideas/help with this, let me know.

Hope this helps.

by donq

You might try setting the "Default" AND Format to "00000000000", then make sure each record already has 0 (zero) entered.

You could change the field to "Text" if there are no exceptions - or you could create a query to build your export recordsetthat converts everything to text before exporting, then export the query result to a fixed length text file?

This discussion is closed to new replies.