语法无效 - 基本VBA查询

时间:2017-11-10 15:28:41

标签: vba ms-access access-vba

希望这是一个简单的修复问题。

我有一个VBA查询,它试图将100个左右的几乎相同(相同列,不同数据)的csv文件导入到一个表中。

每当我尝试运行宏时,它都无法运行并获取

  

语法错误无效

Public Function Import()
Dim strPathFile As String, strFile As String, strPath As String
Dim strTable As String
Dim blnHasFieldNames As Boolean


blnHasFieldNames = True

strPath = "C:\Users\Jason\Downloads\Riskmodels\"

strTable = "table"

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


Do While Len(strFile) > 0
      strPathFile = strPath & strFile
      DoCmd.TransferText TransferType:=acImportDelim, _
      TableName:=strTable, _
      FileName:=strPathFile, _
      HasFieldName:=True

      strFile = Dir()
Loop

End Function

知道为什么这不起作用?

感谢

1 个答案:

答案 0 :(得分:2)

命名参数应为Public Function IsoWeekNumber(d As Date) As String Dim kwtemp As String kwtemp = DatePart("ww", d, vbMonday, vbFirstFourDays) If Len(kwtemp) = 1 Then kwtemp = "0" & kwtemp IsoWeekNumber = kwtemp End Function If Application.International(xlMDY) = True Then HeadlineTemp = Mid(VRHeadline, InStr(VRHeadline, "[") + 1, 10) HeadlineTemp = Replace(HeadlineTemp, ".", "/") HeadlineTemp = Mid(HeadlineTemp, 4, 3) & Left(HeadlineTemp, 2) & Right(HeadlineTemp, 5) VRFirstKW = CDate(HeadlineTemp) HeadlineTempEndKW = Mid(VRHeadline, InStr(VRHeadline, "]") - 10, 10) HeadlineTempEndKW = Replace(HeadlineTempEndKW, ".", "/") HeadlineTempEndKW = Mid(HeadlineTempEndKW, 4, 3) & Left(HeadlineTempEndKW, 2) & Right(HeadlineTempEndKW, 5) VREndKW = CDate(HeadlineTempEndKW) VRKW = "KW" & IsoWeekNumber(VRFirstKW) & "-" & IsoWeekNumber(VREndKW) & "/" & Year(VREndKW) Else 'don't switch position of the month with days HeadlineTemp = Mid(VRHeadline, InStr(VRHeadline, "[") + 1, 10) HeadlineTemp = Replace(HeadlineTemp, ".", "/") VRFirstKW = CDate(HeadlineTemp) HeadlineTempEndKW = Mid(VRHeadline, InStr(VRHeadline, "]") - 10, 10) HeadlineTempEndKW = Replace(HeadlineTempEndKW, ".", "/") VREndKW = CDate(HeadlineTempEndKW) VRKW = "KW" & IsoWeekNumber(VRFirstKW) & "-" & IsoWeekNumber(VREndKW) & "/" & Year(VREndKW)