[英]VB Code not working for .CSV import into access 2007
I am trying to import a .CSV file from a spacific folder in to access. 我正在尝试从一个不常用的文件夹中导入.CSV文件以进行访问。
I have set up my own import specs by importing the first CSV file. 我已经通过导入第一个CSV文件设置了自己的导入规范。 I then writen this code
然后我写这段代码
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
I then connected a button up to run this command and even though it complies okay nothing happens. 然后,我连接了一个按钮来运行此命令,即使它符合要求,也没有任何反应。
Any help would be great. 任何帮助都会很棒。
The line of code 代码行
strFile = Dir(strPath & "*.csv")
does the equivalent of the following at a command prompt: 在命令提示符下执行以下操作:
dir "C:\Users\arbmaint\Desktop\Jumbo start loading test results*.csv"
and if strPath
is the name of a folder then you won't get any matches to files inside the folder without a backslash \\
separator. 如果
strPath
是一个文件夹的名称,然后您将无法获得该文件夹内的文件任意场比赛没有一个反斜杠\\
分隔。 Try this instead: 尝试以下方法:
strFile = Dir(strPath & "\*.csv")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.