OK . ... let's set up the import specification first.
Make a copy of a DAT file, and change the extension to TXT. We'll use this
file to set up the spec.
From your database window, click File | Get External Data | Import. Select
the "*.txt" option for the file type. Browse to the file that we just
renamed. Select it and click Import.
When the wizard window opens, be sure that the Fixed Width option is
selected. Then click the Advanced button at bottom left.
You'll now see a screen that will let you customize the incoming file's
format. Delete all the records that you see there for Field information.
In the first record, put FieldIgnore1 as the name, Text as the data type, 1
as start, 24 as width, and No as indexed.
In the second record, put FieldWant1 as the name, Text as the data type, 25
as start, 4 as width, and No as indexed.
In the third record, put FieldIgnore2 as the name, Text as the data type, 29
as start, 7 as width, and No as indexed.
In the fourth record, put FieldWant2 as the name, Text as the data type, 36
as start, 7 as width, and No as indexed.
In the fifth record, put FieldIgnore3 as the name, Text as the data type, 43
as start, 50 as width, and No as indexed.
In the sixth record, put FieldWant2 as the name, Text as the data type, 93
as start, 5 as width, and No as indexed.
Click the Save As... button, give the specification a name, e.g.,
CurieImportSpec, and then save it by clicking the OK button.
Click the OK button on the window where you'd entered the field info.
Click Next.
This window should show you the "breaks" that will parse the data for you.
If it looks ok, click Next.
This window allows you to select "new table" or "existing table". If you
select "new table", a new table will be created using the filename as its
name, and the fields will be named as you listed in the specification. If
you select "existing table" and then select a table, that table must have
the same number of fields that you put in the specification and they must be
named the same as you did in the specification. If this is not correct, make
the changes in the table and/or specification so that they match (you'll
need to cancel the import step to make changes to the table, then you can
start the import again and use the Advanced butt to get to the spec window,
where you'd click the Specs button in order to select the spec that you'd
created earlier). Click Next.
This window just "shows" you the spec settings. Click Next.
If you selected "new table", this window will let you say whether you want a
primary key or not. Make your choice and click Next.
If you had selected "existing table", this window shows instead of the
"primary key" window, else it is the next window.
At this point, we can stop the import process because you've created and
saved the import specification. Click Cancel.
Now, in your code, where you use TransferText, put the name of the
specification (as a text string: "CurieImportSpec") as the second argument
of the call to the method:
DoCmd.TransferText acImportFixed, "CurieImportSpec", _
"TableName -leave empty if spec creates new table", "PathToFile",
False
The False at the end of the call tells ACCESS that the first record in the
text file does not contain the actual field names. If that record does
contain the field names, then use True instead.
--
Ken Snell
<MS ACCESS MVP>