Link to home
Start Free TrialLog in
Avatar of zimmer9
zimmer9Flag for United States of America

asked on

How would I import a .txt file of fixed length records into an Access table using Access 2003 ?

I am developing an Access application using Access 2003. I have a txt file named C:\Address.txt comprised of the following fields:

field name          field type
------------          ------------
FirstName          Text
MiddleName       Text
LastName          Text

I also have an Access table named tblNameAddress comprised of the following fields:

FirstName                Text
MiddleName             Text
LastName                Text

How would you write VBA code to import the txt file named C:\Address.txt
into the Access table named tblNameAddress.
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image


you can use this command line

DoCmd.TransferText acImportFixed, "ImportSpecificationName", "tblNameAddress", "C:\Address.txt", True
Try using transferText:

docmd.TransferText acImportFixed,,"YourTable", "YoutFileName",true
                                                                                                   ^^--- Field Names in text file
Avatar of zimmer9

ASKER

docmd.TransferText acImportFixed,,"YourTable", "YourFileName",true
                                                                                                   ^^--- Field Names in text file

^^--- Field Names in text file

what does this notation mean ?
If that parameter is set to true, the first line of your file contains the Field Names.  Actual data follows that.
Avatar of zimmer9

ASKER

DoCmd.TransferText acImportFixed, , "tblAddr", "C:\Address.txt", False
--------------------------------------------------------------------------------------
This causes the following error:
Run time error '2511":
The action or method requires a Specification Name argument.
didn't you read my post?

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