0

我需要帮助在访问中打开最后修改的 csv。CSV 文件位于某个文件夹 FF 中。我在下面有一些代码,但错误是在将选择的 csv 文件导入访问中 任何人都可以用这一行想到: DoCmd.TransferText acImportDelim, "", "Tablename", "Availability", True, ""

Private Sub Import_Click()


Dim myDir As String, fn As String, a(), n As Long, Availability As String
Dim myDate As Date, temp As Date

myDir = "C:\Documents and Settings\FF"
fn = Dir(myDir & "\*.csv")


Do While fn <> ""
    temp = CreateObject("Scripting.FileSystemObject").GetFile(myDir & "\" & fn).DateLastModified
    If myDate = 0 Then
        myDate = temp: Availability = myDir & "\" & fn
    Else
        If myDate < temp Then myDate = temp: Availability = myDir & "\" & fn
    End If
    fn = Dir
Loop
If Len(Availability) Then
      If vbYes = MsgBox("Opening Availability File  Name : " & Availability & vbLf & _
    "Last modified on : " & myDate, vbYesNo) Then

       DoCmd.TransferText acImportDelim, "", "Tablename", "Availability", True, ""
    End If
End If
4

1 回答 1

0

您不应该在变量周围加上引号,这会使它们成为字符串:

DoCmd.TransferText acImportDelim, "", "Tablename", Availability, True, ""

您正在导入最旧的文件,因为您说myDate < temp

我会一直使用 FileSystemObject。

于 2012-08-09T09:59:40.953 回答