0

I am trying to import a text file in MSAccess Vba code as below

DoCmd.TransferText acImportDelim, "", "TableName", FileName, True, ""

The file am importing does not have a any headers in it. It is a comma delimited file with just data. The table has column names in it. Now i want to import that file in to this table. When i am trying to import that file using the above code its throwing an error Cannot find col 'X' in the table .(where X is the first row, first column of data in in the input file). Please suugest me some solution or a sample example. Your help is appreciated.

1
  • 1
    Don't pass a zero-length string for the optional arguments -- just omit them: DoCmd.TransferText acImportDelim, , "TableName", FileName. Commented Sep 24, 2011 at 21:12

1 Answer 1

1

If the file has no headers, you should be passing False for the HasFieldNames parameter instead of True:

expression.TransferText(TransferType, SpecificationName, TableName, FileName, HasFieldNames, HTMLTableName, CodePage)

...

HasFieldNames: Use True to use the first row of the text file as field names when importing, exporting, or linking. Use False to treat the first row of the text file as normal data.

http://msdn.microsoft.com/en-us/library/aa220768.aspx

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.