Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    Star Lounger
    Join Date
    Sep 2002
    Location
    Indianapolis, Indiana, USA
    Posts
    80
    Thanks
    1
    Thanked 0 Times in 0 Posts

    application.filesearch (2002 SP3)

    I was reaquainting myself with filesearch using the following code. The code returns false, ie no files found and I can't seem to find my error. Yes the directory exists and there are *.dat files in it.

    Sub datimport()
    Dim i As Integer

    Set fs = Application.FileSearch
    With fs
    .NewSearch
    .LookIn = "C:test"
    .filename = "*.dat"
    .Searchsubfolders = True
    If .Execute() > 0 Then
    MsgBox "There were " & .FoundFiles.Count & _
    " file(s) found."
    For i = 1 To .FoundFiles.Count
    MsgBox .FoundFiles(i)
    Next i
    Else
    MsgBox "There were no files found."
    End If
    End With

    End Sub

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

    Re: application.filesearch (2002 SP3)

    Your code works for me with the appropriate path and extension substituted, so the code itself is OK. I note that you haven't declared fs, you should have

    Dim fs As FileSearch

    but that should not result in no files being found. Does the code work if you use another path and/or another extension?

  3. #3
    Star Lounger
    Join Date
    Sep 2002
    Location
    Indianapolis, Indiana, USA
    Posts
    80
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: application.filesearch (2002 SP3)

    No, varying the directory does not work and no change in outcome with the explicit variable declaration.
    I started out with a subdirectory and created test to see if that was the problem. I Set a breakpoint at execute() and checked the Locals window and all of the variables are correctly set.

    I also added ".FileType = msoFileTypeAllFiles" to no avail.

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

    Re: application.filesearch (2002 SP3)

    I take it that you have also tried searching for a different extension (.mdb or .doc, for example).

    It seems very weird, perhaps you should try a repair installation of Office XP...

  5. #5
    Star Lounger
    Join Date
    Sep 2002
    Location
    Indianapolis, Indiana, USA
    Posts
    80
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: application.filesearch (2002 SP3)

    I've tried a repair install, copying the code out to a new database, tried different extensions. Seems to be beyond my Office XP install.

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

    Re: application.filesearch (2002 SP3)

    The code is not specific to Access. Does it also fail if you copy it into a module in Word or Excel and run it?

  7. #7
    Star Lounger
    Join Date
    Sep 2002
    Location
    Indianapolis, Indiana, USA
    Posts
    80
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: application.filesearch (2002 SP3)

    good thought. Yes it does fail. But it does not fail on other machines, so I am back to something wrong with my machine. I just uninstalled XP office and used a cleanup program and I still have the error. Other code seems to run. I have some old routines built in 97 that I am going to bring in and try.

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

    Re: application.filesearch (2002 SP3)

    How can you run the code at all if you uninstalled Office? <img src=/S/scratch.gif border=0 alt=scratch width=25 height=29>

  9. #9
    3 Star Lounger
    Join Date
    Apr 2002
    Location
    Redditch, Worcestershire, England
    Posts
    233
    Thanks
    0
    Thanked 22 Times in 21 Posts

    Re: application.filesearch (2002 SP3)

    I have vague memories of FileSearch playing up in my previous employment when I was running it on an NT box - something to do with the options set in Windows Explorer limiting the results - e.g. show hidden files, hide system files etc.

    Can you get your code to work with an "innocent" extension like .txt or .doc?

    Jeremy

  10. #10
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: application.filesearch (2002 SP3)

    I wonder if you could be running into the issue of extensions? Access 2000 and higher doesn't recognize .dat as a legitimate extension for a text file unless the registry is tweaked to allow it. What happens if you run the same code using .txt on a folder with text files?
    Charlotte

  11. #11
    Star Lounger
    Join Date
    Sep 2002
    Location
    Indianapolis, Indiana, USA
    Posts
    80
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: application.filesearch (2002 SP3)

    Hi all. I am back on this problem.The application.fileseach does not find any file on my machine and am looking for some debugging ideas. Filesearch does not work in excel or access. Yet I do not have any problems with filesearching when I do not use vb code. I uninstalled Office XP, ran the MS clean up program, reinstalled Office XP and I still have the same problem. I created the following test file and 3 text files and this works fine on other computers. The .execute() > 0 evaluates false.

    Anyone have any debugging ideas?

    test code:

    Sub filesearchtest()

    With Application.FileSearch
    .NewSearch
    .LookIn = "C:"
    .SearchSubFolders = False
    .Filename = "*.txt"
    .MatchTextExactly = False
    '.FileType = msoFileTypeAllFiles
    If .Execute() > 0 Then
    MsgBox "There were " & .FoundFiles.Count & _
    " file(s) found."
    For i = 1 To .FoundFiles.Count
    MsgBox .FoundFiles(i)
    Next i
    Else
    MsgBox "There were no files found."
    End If

    End With

    End Sub

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

    Re: application.filesearch (2002 SP3)

    There are some indications in the newsgroups that the Indexing Service in Windows XP may interfere with FileSearch. You might check if the Indexing Service is running, and if so, stop it, to see if that helps.
    - Select Start > Control Panel.
    - Click Performance and Maintenance, click Administrative Tools, and then open Computer Management.
    - Expand the tree in the left hand pane until you see Indexing Service under Services and Applications.
    - If Action | Stop is enabled, select this menu option to stop the Indexing Service.

    Otherwise, no idea. Sorry.

  13. #13
    Star Lounger
    Join Date
    Sep 2002
    Location
    Indianapolis, Indiana, USA
    Posts
    80
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: application.filesearch (2002 SP3)

    (Edited by HansV to make URL clickable - see <!help=19>Help 19<!/help>)

    Bingo, worked and it turns out the other machine did not have it truned on. So I am going to move the Dir() based on the recommendations in the following article:

    http://support.microsoft.com/default.aspx?...KB;EN-US;259738

  14. #14
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: application.filesearch (2002 SP3)

    Do you need any references set, I get a compile error when trying to use:
    dim fs as filesearch

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

    Re: application.filesearch (2002 SP3)

    You need to have a reference to the Microsoft Office 10.0 Object Library (the 10.0 is for Office XP, use 7.0 for Office 97, 8.0 for Office 2000 and 11.0 for Office 2003).

Page 1 of 2 12 LastLast

Posting Permissions

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