ACC2000: Unable to Import Data from a Fixed-Width Text File (209698)



The information in this article applies to:

  • Microsoft Access 2000

This article was previously published under Q209698
Novice: Requires knowledge of the user interface on single-user computers.

This article applies to a Microsoft Access database (.mdb) and to a Microsoft Access project (.adp).

SYMPTOMS

You may be unable to import any data from a fixed-width text file.

CAUSE

Each record in a fixed-width text file must be separated from the next record by a carriage return or line feed, and all the records must contain the same number of characters. The text file that you are trying to import may not meet these requirements.

RESOLUTION

Modify the text file to ensure that all records meet the following requirements:
  • Each record is on a different line.
  • Each record contains the same number of characters.

MORE INFORMATION

Microsoft Access cannot import fixed-width text records that are not delimited by a carriage return or line feed.

Mainframe users may be familiar with long strings of data where the first x number of characters are the first record, the next x number of characters are the second record, and so on. To import these records into Microsoft Access, you must ensure that each record is on its own line with a carriage return or line feed at the end of each record.

For example, consider the following string of characters:

lastnamefirstnameagelastnamefirstnameagelastnamefirstnameage

You cannot import these records into Microsoft Access without modification. If you try to import this string as a fixed-width text file, you either create an empty table, or you are unsuccessful and may need to repair your database.

To modify the file using code, follow these steps:
  1. Read the file in Binary mode with a fixed-length string that is the same length as the record.
  2. Write each string to a new file that is open for sequential output.
  3. Repeat steps 1 and 2 until you reach the end of the file.
Microsoft Access can import the following records:

lastnamefirstnameage
lastnamefirstnameage
lastnamefirstnameage

To import a file containing records like these, follow these steps:
  1. On the File menu, point to Get External Data, and then click Import.
  2. In the Import dialog box, change the Files of type setting to Text Files.
  3. Select the text file that you want to import, and then click Import. This action starts the Import Text Wizard.
  4. In the Import Text Wizard, click the Advanced button.
  5. Type the following settings for Field Information:
       Field Name   Data Type   Start   Width
       --------------------------------------
       Last         Text        1       8
       First        Text        9       9
       Age          Number      18      3
    					
  6. Click Save As and save this specification as Test. Then, click OK.
  7. Continue through the wizard by clicking Next, and then click Finish to import the file.

REFERENCES

For more information about importing data, click Microsoft Access Help on the Help menu, type import data in the Office Assistant or the Answer Wizard, and then click Search to view the topics returned.

Modification Type:MinorLast Reviewed:7/13/2004
Keywords:kb3rdparty kbprb KB209698