系统对象方法问题

System Object Method issue

我今天才了解 FSO,所以我正在尝试将其实施到我的数据库中,以便每小时导入统计信息(一个新文件每小时出现在文件夹中)

当我 运行 代码找到文件但没有导入数据并抛出 运行time 3011 错误

我的模块代码:

  Function getFilename(path As String) As String
Dim objFSO As Object
Dim objFolder As Object
Dim objFile As Object
Dim dateModified As Date

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(path)

For Each objFile In objFolder.Files
Debug.Print objFile.Name
If InStr(objFile.Name, "hourly performance") > 0 And Not Left(objFile.Name, 1) = "~" Then
    If objFile.datelastmodified > dateModified Then
    dateModified = objFile.datelastmodified
    getFilename = objFile.Name
    End If

End If

Next objFile

End Function

我的 VBA 代码是:

 Dim strFilename As String

strFilename = getFilename("C:\stats folder hourly\")

' Import Weekly stats
            DoCmd.TransferSpreadsheet transfertype:=acImport, SpreadsheetType:=10, _
            tablename:="Weekly", FileName:=strFilename, _
            Hasfieldnames:=True, Range:="AgentActivity CSV!"

错误:

Microsoft access database engine could not find the object 'FILENAME' Make sure the object exists and that you spell the name and the path name correctly

帮助

尝试更改

getFilename = objFile.Name

getFilename = objFSO.GetAbsolutePathName(objFile)

wich 会给你像 c:\folder\file.ext

这样的绝对路径

我终于解决了问题

    DoCmd.TransferSpreadsheet transfertype:=acImport, SpreadsheetType:=10, _
    tablename:="Hourly", FileName:="FILPATH" & hourly & "", _
    Hasfieldnames:=True, Range:="AgentActivity CSV!"