2014-02-20 20 views
0

我想从一个文件夹中导入一个.CSV文件进行访问。VB代码不工作.CSV导入访问2007

我已经通过导入第一个CSV文件设置了自己的导入规格。然后我writen这个代码

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 

我再连接一个按钮向上运行此命令,即使它符合还好没有任何反应。

任何帮助将是伟大的。

回答

0

的代码

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

行确实在命令提示符下的等价的:

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

,如果strPath是一个文件夹的名称,那么你不会得到任何比赛到文件里面没有反斜杠的文件夹\分隔符。试试这个:

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