2014-02-20 2 views
0

Я пытаюсь импортировать файл .CSV из промежуточной папки для доступа.Код VB не работает для импорта .CSV в Access 2007

Я создал свои собственные спецификации импорта, импортировав первый 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 

Затем я подключил кнопку до запуска этой команды и даже если она не соответствует ладно, ничего не происходит.

Любая помощь будет отличной.

ответ

0

Строка кода

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

делает эквивалент следующее в командной строке:

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

и если strPath это имя папки, то вы не получите никаких совпадений к файлам внутри папка без обратной косой черты \ разделитель. Попробуйте это вместо:

strFile = Dir(strPath & "\*.csv") 
Смежные вопросы