Results 1 to 2 of 2
  1. #1
    togo is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2012
    Posts
    83

    Nested File Search subroutine not working correctly

    Here's what I got.

    Code:
    sPath = "C:\TEST\"
    sPathMember = Dir(sPath, vbDirectory) ' Get the first entry
    bracketFound = False
    JobNumberHasBeenFound = False
    NextDirectoryFound = False
    A = 2
    c = 1
    DirectorySearch:
    Do While sPathMember <> ""   ' Start the loop
      ' Be sure to skip over these directory markers
      If sPathMember <> "." And sPathMember <> ".." Then
        If Right(sPathMember, 1) <> "." And Right(sPathMember, 2) <> ".." Then
            'Test if directory
            
            If sPathMember = "" Then
                GoTo LeftDown
            End If
            If (GetAttr(sPath & sPathMember) And vbDirectory) = vbDirectory Then
                sPath = sPath & sPathMember & "\"
                sPathMember = Dir(sPath, vbDirectory)
            End If
        End If
       End If
       MsgBox "Loop 1: " & sPath & sPathMember
       sPathMember = Dir
    Loop
    LeftDown:
    If sPathMember = "" Then
        ' reached end of subdirectories
        ' go back and down
        A = 1
        bracketFound = False
        Do While bracketFound = False
        If Mid(sPath, Len(sPath) - A, 1) = "\" Then
            bracketFound = True
            sPath = Left(sPath, Len(sPath) - A)
        End If
        If bracketFound = False Then A = A + 1
        Loop
        A = 2
        sPathMember = Dir(sPath, vbDirectory)
        
        Do While sPathMember <> ""
        
            If sPathMember <> "." And sPathMember <> ".." Then
                If Right(sPathMember, 1) <> "." And Right(sPathMember, 2) <> ".." Then
                    If (GetAttr(sPath & sPathMember) And vbDirectory) = vbDirectory Then
                    NewPath = sPath & sPathMember
                    If currentPath = NewPath Then GoTo NotThisFolder
                    MsgBox "Current: " & currentPath & " New: " & NewPath
                    currentPath = sPath & sPathMember
                    GoTo DirectorySearch:
                    End If
                End If
            End If
    NotThisFolder:
            sPathMember = Dir
        Loop
    MovedDown:
    End If
    ExitFolderSearch:
    almost seemed to work at first but can't seem to find any clear examples of how to do this on the net.



    It's just supposed to do a folder search through all the folders on the hard drive, searching for a folder name that contains the job name. Spent the day troubleshooting it and seem to be getting nowhere. Any ideas? thanks

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Have you step debugged? Follow the code as it executes, see where it deviates from expected behavior. Fix, repeat.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Sort function not working correctly
    By kristyspdx in forum Reports
    Replies: 2
    Last Post: 10-09-2012, 11:04 AM
  2. Condtion not working correctly
    By hawkins in forum Access
    Replies: 3
    Last Post: 09-07-2011, 02:59 PM
  3. Calling Access VBA subroutine from an Excel VBA subroutine
    By richard_yolland in forum Programming
    Replies: 0
    Last Post: 02-16-2011, 11:30 AM
  4. Split Form not working correctly
    By Brian62 in forum Access
    Replies: 29
    Last Post: 02-16-2010, 05:43 PM
  5. Search field is not working correctly
    By jakeao in forum Programming
    Replies: 9
    Last Post: 05-18-2009, 07:47 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