Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Mar 2006
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    289
    Thanks
    0
    Thanked 1 Time in 1 Post

    Retrieve File Modified Date (2003 sp2)

    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
    Thanks
    chuck

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Retrieve File Modified Date (2003 sp2)

    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

  3. #3
    3 Star Lounger
    Join Date
    Mar 2006
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    289
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Retrieve File Modified Date (2003 sp2)

    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. <img src=/S/dizzy.gif border=0 alt=dizzy width=15 height=15>
    Thanks
    chuck

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •