【发布时间】:2019-10-17 11:52:34
【问题描述】:
我之前使用以下代码将多个 csv 文件从一个文件夹导入到 Access 数据库中的 1 个表中。但是,这次每个文件的第一行包含一个帐号,并且列标题在第 2 行。所以每个文件的第一行不同,并且此代码在“DoCmd.TransferText acImportDelim, , strTable, strPathFile, blnHasFieldNames"
如何排除每个文件的第一行?
我尝试将“blnHasFieldNames”更改为 False,希望代码能够接受第 1 行中的任何差异,但这不起作用。
将 strPathFile 作为字符串、strFile 作为字符串、strPath 作为字符串进行调暗 将 strTable 调暗为字符串,将 strBrowseMsg 调暗为字符串 将 blnHasFieldNames 设为布尔值
' Change this next line to True if the first row in EXCEL worksheet
' has field names
blnHasFieldNames = True
strBrowseMsg = "Table Name"
strPath = "FilePath"
If strPath = "" Then
MsgBox "No folder was selected.", vbOK, "No Selection"
Exit Sub
End If
' Replace tablename with the real name of the table into which
' the data are to be imported
strTable = "Table Name"
strFile = Dir(strPath & "\*.csv")
Do While Len(strFile) > 0
strPathFile = strPath & "\" & strFile
DoCmd.TransferText acImportDelim, , strTable, strPathFile, blnHasFieldNames
' Uncomment out the next code step if you want to delete the
' EXCEL file after it's been imported
' Kill strPathFile
strFile = Dir()
Loop
我得到的错误是(xxxxxx=我使用了这个而不是帐户名)
运行时错误“2391”: 目标表“表名”中不存在字段“xxxxxxxxx”
【问题讨论】: