• Retrieve File Modified Date (2003 sp2)

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Retrieve File Modified Date (2003 sp2)

    Author
    Topic
    #449216

    I need a generic function that I can use to retrieve the modified date of a file. Here’s my best shot and it gives me the error, “Object variable or with block variable not set”. It stops at line, Set objFolderItem = objFolder.ParseName(strFilename) which confuses me because it holds the correct value.

    Public Function GetFileModDate(strFolder As String, strFilename As String)
    Dim strValue As Date
    strFolder = “Ppnta661PAGroupTOSTop Technical ServicesSpecial Asset Reports”
    strFilename = “REALEST.txt”
    Set objShell = CreateObject(“Shell.Application”)

    Set objFolder = objShell.NameSpace(strFolder)
    Set objFolderItem = objFolder.ParseName(strFilename)

    strValue = objFolder.GetDetailsOf(objFolderItem, 3)

    If strValue <= Date – 7 Then
    MsgBox "The file is not current"
    Else
    MsgBox "The file is Current"
    End If
    End Function

    Viewing 0 reply threads
    Author
    Replies
    • #1100814

      Did you put the values of strFolder and strFilename inside the function as an example? Otherwise it makes no sense to pass strFolder and strFilename to the function since their values will be overwritten in the function.
      Also, your function doesn’t return a value, so you might as well use a procedure.

      The problem in your function is that objFolder is still Nothing after the line Set objFolder = objShell.NameSpace(strFolder).

      Try this instead:

      Public Function GetFileModDate(strFile As String) As Date
      GetFileModDate = CreateObject(“Scripting.FileSystemObject”).GetFile(strFile).DateLastModified
      End Function

      Use it like this:

      Sub TestCurrent()
      Dim strFile As String
      Dim datValue As Date
      strFile = “Ppnta661PAGroupTOSTop Technical ServicesSpecial Asset ReportsREALEST.txt”
      datValue = GetFileModDate(strFile)
      If datValue <= Date – 7 Then
      MsgBox "The file is not current"
      Else
      MsgBox "The file is Current"
      End If
      End Sub

      • #1100819

        I started out with the values of strFolder and strFileName inside the function and should have removed them in my post. I want to pass them when I call the function.

        What you have given works perfectly. There sure are a lot of ways to do things in VB. dizzy

    Viewing 0 reply threads
    Reply To: Retrieve File Modified Date (2003 sp2)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: