Results 1 to 5 of 5
  1. #1
    JeroenMioch's Avatar
    JeroenMioch is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Location
    Den Haag, Netherlands
    Posts
    368

    Looking for timevalue in filename

    Hey guys,



    I have a function that counts files from disk recursively.
    The files searched for have a date in the name, and the function will allready count files from today.
    This works well but now i have to count files that have a timestamp in the name between 0800 - 1800 hrs.
    This is an example of the name of the file im searching for :

    22-01-2016 1533 Test.pdf

    As you can see the "time" is 1533 hrs and this file needs to be counted. where as a time lets say 0745 does not.
    I tried putting a between statement inside it, but it doesnt work.

    This is the function :

    Code:
        Dim colFiles As New Collection
        RecursiveDir colFiles, "I:\MyDirecory", "" & Format(Date, "dd/mm/yyyy") & "*.pdf", True
    
    
        Dim vFile As Variant
        For Each vFile In colFiles
        ctrlTest = colFiles.Count
        Next vFile
    Function :

    Code:
    Public Function RecursiveDir(colFiles As Collection, _
                                 strFolder As String, _
                                 strFileSpec As String, _
                                 bIncludeSubfolders As Boolean)
    
    
        Dim strTemp As String
        Dim colFolders As New Collection
        Dim vFolderName As Variant
    
    
        'Add files in strFolder matching strFileSpec to colFiles
        strFolder = TrailingSlash(strFolder)
        strTemp = Dir(strFolder & strFileSpec)
        Do While strTemp <> vbNullString
            colFiles.Add strFolder & strTemp
            strTemp = Dir
        Loop
    
    
        If bIncludeSubfolders Then
            'Fill colFolders with list of subdirectories of strFolder
            strTemp = Dir(strFolder, vbDirectory)
            Do While strTemp <> vbNullString
                If (strTemp <> ".") And (strTemp <> "..") Then
                    If (GetAttr(strFolder & strTemp) And vbDirectory) <> 0 Then
                        colFolders.Add strTemp
                    End If
                End If
                strTemp = Dir
            Loop
    
    
            'Call RecursiveDir for each subfolder in colFolders
            For Each vFolderName In colFolders
                Call RecursiveDir(colFiles, strFolder & vFolderName, strFileSpec, True)
            Next vFolderName
        End If
    
    
    End Function
    
    
    
    
    Public Function TrailingSlash(strFolder As String) As String
        If Len(strFolder) > 0 Then
            If Right(strFolder, 1) = "\" Then
                TrailingSlash = strFolder
            Else
                TrailingSlash = strFolder & "\"
            End If
        End If
    End Function

    Any suggestions ?

  2. #2
    cyanidem's Avatar
    cyanidem is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Nov 2015
    Location
    Consett, UK
    Posts
    270
    Code:
    If Val(YourTimeString) >= 800 And Val(YourTimeString) <= 1800 Then    
        Something
    Else
        SomethingElse
    End If

  3. #3
    JeroenMioch's Avatar
    JeroenMioch is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Location
    Den Haag, Netherlands
    Posts
    368
    I wish it was that simple
    I would still have to define greeater, smaller then or between in the string itself.
    So, something like this :
    Code:
    "I:\MyDirecory", "" & Format(Date, "dd/mm/yyyy") & " " & Between format(Time, "0800") and format(Time, "1800") & "*.pdf"


    But above code won't work, i have tried many variants.

  4. #4
    JeroenMioch's Avatar
    JeroenMioch is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Location
    Den Haag, Netherlands
    Posts
    368
    Anyone know a solution ?
    Any hints are helpfull.

  5. #5
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    The time is built into the file name in columns 12-15, but nowhere does your code extract that value to check it.

    You should have a statement something like:

    if Val(mid(strtemp,12,4)) >= 800 AND Val(mid(strtemp,12,4)) <= 1600 then
    ...
    endif

    to check the time of the files.

    (Between can't be used here)

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

Similar Threads

  1. Comma in filename?
    By lithium in forum Programming
    Replies: 4
    Last Post: 10-23-2014, 01:34 PM
  2. TimeValue in Excel VS Access VBA
    By Hasher in forum Programming
    Replies: 1
    Last Post: 07-17-2014, 09:36 AM
  3. =TimeValue(Now()) Not Running Live
    By excellenthelp in forum Access
    Replies: 3
    Last Post: 06-27-2014, 01:19 PM
  4. TimeValue
    By turnbuk in forum Queries
    Replies: 9
    Last Post: 08-10-2011, 02:44 PM
  5. Filename displaying with image
    By Rob Parker in forum Forms
    Replies: 2
    Last Post: 01-13-2010, 05:05 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