Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

ACC2000: Exporting to Fixed-Width Text File Left-Aligns Numbers


View products that this article applies to.

This article was previously published under Q201115
Moderate: Requires basic macro, coding, and interoperability skills.

For a Microsoft Access 2002 version of this article, see 288572 (http://support.microsoft.com/kb/288572/EN-US/ ) .

↑ Back to the top


Symptoms

When you export a table that contains a Number or a Currency field to a fixed-width text file, the numbers in the table become left-aligned.

↑ Back to the top


Cause

Because the numbers are being exported to a fixed-width text file, Microsoft Access pads zeros to the right of the number until it meets the proper field width.

↑ Back to the top


Resolution

To make the numbers align with the decimal and pad zeros to the left instead of to the right, you must first determine the maximum length of the Number or Currency field. Use this number of zeros in the Format() function below. Next, you must determine the number of decimal places that the field in question uses. Use this value to determine how many zeros to place after the decimal point in the Format() function below. Finally, create a query based on the following Microsoft Access SQL statement:
SELECT DISTINCTROW
Format([MyNumber],"0000.00") AS [Expr1]
INTO [MyNewTable]
FROM [MyOldTable];
For this example, the SQL statement assumes that you have the following table:
   Table: MyOldTable
   -----------------
   Field Name: MyNumber
   Data Type: Currency
				
It also assumes that the longest value in the MyNumber field is 7 characters (including the decimal point and decimal places) and that each value has two decimal places. This Microsoft Access SQL statement, when typed in the SQL window in the query-by-example (QBE) grid, makes a new table called MyNewTable with the MyNumber field padded to the left with zeros.

When you use this Microsoft Access SQL statement in a query, the data from MyOldTable is formatted with decimal justification and placed in a new table called MyNewTable.

↑ Back to the top


More information

Steps to Reproduce Behavior

  1. Create the following table:
          Table: MyOldTable
          -----------------
          Field Name: MyNumber
          Data Type: Currency
    					
  2. Enter the following numbers in the table:
    34.5
    123.56
    4578.90
  3. On the File menu, click Export and select the Text Files option. When the Export Text Wizard prompts you, click Fixed Width, and then click Finish.
  4. Open the exported text file in any text editor, such as Notepad, and view the numbers. Note that they appear as follows:
    $34.5000
    $123.560
    $4578.90

↑ Back to the top


References

For additional information, please see the following article in the Microsoft Knowledge Base:
210052 ACC2000: How to Export Right- or Left-Aligned Fields to a Text File

↑ Back to the top


Keywords: KB201115, kb3rdparty, kbprb

↑ Back to the top

Article Info
Article ID : 201115
Revision : 2
Created on : 6/30/2004
Published on : 6/30/2004
Exists online : False
Views : 361