Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2005
    Posts
    1

    Unanswered: HELP!! Using Findfile function!!??

    Hello there folks

    I'm kinda totally newbie using both Access and VB.

    My knowlege in programming is somehow restricted to
    C, C++, Pascal, Delphi and Old and good QuickBasic :-)

    So, I'm feeling a little lost inside Access' modules, macros,
    tables, forms and so on.

    What I need is something like described below:
    - Use some Findfile function to return a list of
    existing files inside some given path, using some kind
    of wildcards (*.txt or *.*)

    When searching Access' help files I figured out this function:
    - Application.Filesearch

    But I don't know how to use it, as every time I compil it, I
    get errors like "Invalid property use" (i actually translated it
    from portuguse-BR, so it may differ from current english message)

    Could anyone help me with this? I think its kind of really easy
    to you non-newbie VB programmers to figure this out.

    The SUB I have done which is spotting that error is the following:


    ' ======
    Private Sub MyListFiles()

    Dim i As Integer

    Application.FileSearch
    Application.NewSearch
    Application.LookIn = "C:\Anypath"
    Application.SearchSubFolders = False
    Application.FileName = "*.txt"
    Application.MatchAllWordForms = True
    Application.FileType = msoFileTypeAllFiles

    If Application.Execute() > 0 Then
    MsgBox "Found " & .FoundFiles.Count & _
    " file(s) int this path."

    For i = 1 To Application.FoundFiles.Count
    'Here, each file is found would be inserted into a Listbox,
    'but it is not the problem, as I know how to do it.
    Next i
    Else
    MsgBox "No file found."
    End If

    End Sub
    '========


    Other error I am coming with is about the msoFileTypeAllFiles CONSTANT,
    which it does not recognize and I dont know if it is requesting a LIB to be
    declared or what should it be and how to declare it....

    Any help?????

  2. #2
    Join Date
    Feb 2004
    Location
    Chicago, IL
    Posts
    1,312
    I have had problems with FileSearch in the past. I use Dir().

    To look for a file with or without a wildcard:

    Dim strFilename as string

    strFilename = Dir("C:\Program Files\*.exe")

    This statement returns the first filename matching the wildcard. If there are no files that match it returns and empty string.

    To get all of the files that match you need to loop:

    Do While strFilename <> ""
    'Do stuff
    strFilename=Dir()
    Loop

Posting Permissions

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