MS Access VBA 导入文本文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7531132/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
MS Access VBA import text File
提问by S..
I am trying to import a text file in MSAccess Vba code as below
我正在尝试在 MSAccess Vba 代码中导入一个文本文件,如下所示
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.
正在导入的文件中没有任何标题。它是一个逗号分隔的文件,只有数据。该表中有列名。现在我想将该文件导入到该表中。当我尝试使用上述代码导入该文件时,它会抛出错误无法在表中找到 col 'X'。(其中 X 是输入文件中的第一行,第一列数据)。请给我一些解决方案或示例。感谢您的帮助。
回答by stuartd
If the file has no headers, you should be passing False for the HasFieldNames parameter instead of True:
如果文件没有标题,您应该为 HasFieldNames 参数传递 False 而不是 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.
expression.TransferText(TransferType, SpecificationName, TableName, FileName, HasFieldNames, HTMLTableName, CodePage)
...
HasFieldNames:使用 True 可在导入、导出或链接时使用文本文件的第一行作为字段名称。使用 False 将文本文件的第一行视为普通数据。