Results 1 to 2 of 2
  1. #1
    Coolpapabell is offline Novice
    Windows Vista Access 2007
    Join Date
    Jul 2009
    Posts
    19

    DoCmd.TransferText only if file is new

    Can Access determine if a text file's time stamp is less than 24 hours old before choosing to import the file with a DoCmd.TransferText command?



    A delimited text file should be updated daily and I only want the file's contents imported if the file is new.

    Thank you

  2. #2
    dcrake's Avatar
    dcrake is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Aug 2009
    Posts
    435
    Here is a module Save as ModFSO

    Code:
     
    Function FSODateLastModified(AnyFile As String) As String
    Dim FSO As New FileSystemObject, FileInfo As File
    If Dir(AnyFile) <> "" Then
        Set FileInfo = FSO.GetFile(AnyFile)
        FSODateLastModified = CStr(FileInfo.DateLastModified)
    Else
        FSODateLastModified = "Unknown"
    End If
     
    End Function
     
    Function FSOFindFiles(sFol As String, sFile As String)
    Dim tFld As Folder, tFil As File, FileName As String
    Dim DLM As String, tPath As String
    Dim fld As Folder, fType As String
     
    Dim FSO As New FileSystemObject, FileInfo As File
     
       On Error GoTo Catch
       If FSO.FolderExists(sFol) Then
       Set fld = FSO.GetFolder(sFol)
       FileName = Dir(FSO.BuildPath(fld.Path, sFile), vbNormal Or vbReadOnly)
     
       While Len(FileName) <> 0
          FindFile = FindFile + FileLen(FSO.BuildPath(fld.Path, FileName))
          tPath = FSO.BuildPath(fld.Path, FileName)
            Set FileInfo = FSO.GetFile(tPath)
            DLM = CStr(FileInfo.DateLastModified)
            fType = CStr(FileInfo.Type)
     
        If IsLoaded("FrmWzdMainDetails") Then
            If Right(FileName, 3) <> "tmp" Then
                FrmWzdMainDetails.ctList1.AddItem FileName + ";" + DLM + ";" + fType
            End If
        End If
          FileName = Dir()
          DoEvents
       Wend
       End If
       Exit Function
    Catch:  FileName = ""
           Resume Next
    End Function
    Function FSOFindDocs(sFol As String, sFile As String)
    Dim tFld As Folder, tFil As File, FileName As String
    Dim DLM As String, tPath As String
    Dim fld As Folder, fType As String
    Dim FSO As New FileSystemObject, FileInfo As File
     
       On Error GoTo Catch
       Set fld = FSO.GetFolder(sFol)
       FileName = Dir(FSO.BuildPath(fld.Path, sFile), vbNormal Or vbHidden Or vbSystem Or vbReadOnly)
     
       While Len(FileName) <> 0
          FindFile = FindFile + FileLen(FSO.BuildPath(fld.Path, FileName))
          tPath = FSO.BuildPath(fld.Path, FileName)
            Set FileInfo = FSO.GetFile(tPath)
            DLM = CStr(FileInfo.DateLastModified)
            fType = CStr(FileInfo.Type)
     
     
       '     FrmContractDetails.ctList4.AddItem FileName + ";" + DLM + ";" + fType
          FileName = Dir()
          DoEvents
       Wend
       Exit Function
    Catch:  FileName = ""
           Resume Next
    End Function
    Function PathExists(sFol As String) As Boolean
       Dim FSO As New FileSystemObject
       PathExists = FSO.FolderExists(sFol)
    End Function
    Function CreateNewFolder(sFol As String)
       Dim FSO As New FileSystemObject
       FSO.CreateFolder sFol
    End Function
    Function CopyFiles(sDoc As String, dDoc As String)
       Dim FSO As New FileSystemObject
       FSO.CopyFile sDoc, dDoc, True
     
     
    End Function
    You can use the date last modified to compare the dates. You may also need to reference the Miscrosoft Scripting Runtime object.

    David

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Problem with DoCmd.RunSQL
    By Peter01 in forum Programming
    Replies: 2
    Last Post: 09-10-2009, 07:11 PM
  2. docmd.runsql not working
    By Rameez in forum Programming
    Replies: 3
    Last Post: 08-07-2009, 10:07 AM
  3. DoCmd.OpenForm Modification
    By alsoto in forum Forms
    Replies: 6
    Last Post: 05-01-2009, 07:28 AM
  4. Upload file inside .mdb database file
    By havish in forum Access
    Replies: 0
    Last Post: 07-30-2008, 07:35 AM
  5. DoCmd.SendObject Help
    By bgreer5050 in forum Programming
    Replies: 0
    Last Post: 01-12-2007, 06:27 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums