0

i need help with open last modified csv in access. Csv files are in some folder FF. I have some code below, but error is in import chosen csv file into access Can anyone idea with this line: 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
Erik A
  • 31,639
  • 12
  • 42
  • 67
lama27
  • 59
  • 1
  • 1
  • 6

1 Answers1

0

You should not put quotes around variables, that makes them strings:

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

You are importing the oldest file, because you say myDate < temp

I would have use the FileSystemObject throughout.

Fionnuala
  • 90,370
  • 7
  • 114
  • 152