【问题标题】:VB Code not working for .CSV import into access 2007VB 代码不适用于 .CSV 导入 access 2007
【发布时间】:2014-02-21 01:16:49
【问题描述】:

我正在尝试从一个空间文件夹中导入一个 .CSV 文件以供访问。

我通过导入第一个 CSV 文件设置了自己的导入规范。然后我写了这段代码

Sub ImportCSVFiles()
    Dim strPathFile As String, strFile As String, strPath As String
    Dim strTable As String
    Dim blnHasFieldNames As Boolean
    Const IMPORT_SPEC = "Megger Readings Import Specification"
' Change this next line to True if the first row in EXCEL worksheet
' has field names
    blnHasFieldNames = True

' Replace C:\Documents\ with the real path to the folder that
' contains the csv files
    strPath = "C:\Users\arbmaint\Desktop\Jumbo start loading test results"

' Replace tablename with the real name of the table into which
' the data are to be imported
    strTable = "Test Results"

    strFile = Dir(strPath & "*.csv")
    Do While Len(strFile) > 0
    strPathFile = strPath & strFile
    DoCmd.TransferText acImportDelim, "Megger Readings Import Specification", strTable, strPathFile, blnHasFieldNames


 Kill strPathFile

strFile = Dir()
Loop

End Sub

然后我连接了一个按钮来运行此命令,即使它符合要求,也没有任何反应。

任何帮助都会很棒。

【问题讨论】:

    标签: ms-access csv ms-access-2007 vba


    【解决方案1】:

    代码行

    strFile = Dir(strPath & "*.csv")
    

    在命令提示符处执行以下等效操作:

    dir "C:\Users\arbmaint\Desktop\Jumbo start loading test results*.csv"
    

    如果strPath 是文件夹的名称,那么如果没有反斜杠\ 分隔符,您将无法匹配inside 文件夹中的文件。试试这个:

    strFile = Dir(strPath & "\*.csv")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-09-07
      • 2011-03-04
      • 2020-05-14
      • 2016-05-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多