Results 1 to 6 of 6
  1. #1
    3 Star Lounger
    Join Date
    Dec 2001
    Location
    Schenectady, New York, USA
    Posts
    273
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How do I get a form to display files in a director (MS Access 2000)

    I have an application that reads text file of the NYS Budget Bills and appends to a table all the items for a particular fund. Currently the user has to enter the drive and path to the file. I would like to create a listbox of all the '*.txt" files in a directory. Does anyone know how I can search a directory to obtain the file names. I have looked at the Application.FileSearch object but the 'FoundFiles' property is only valid for Office and not Access. <img src=/S/brickwall.gif border=0 alt=brickwall width=25 height=15>

    This is what I was trying to do:

    Set fs = Application.FileSearch
    With fs
    fs.LookIn = "J:BSMemItemsdb"
    .fileName = "*.txt"
    If .Execute > 0 Then
    For i = 1 To fs.fileName
    Me.lstBxFile.Column(0, i - 1) = .foundfiles(i)
    Next i
    Else
    MsgBox "There were no files found."
    End If
    End With

    Thank you
    Don
    <img src=/S/flags/USA.gif border=0 alt=USA width=30 height=18> <img src=/S/flags/NewYork.gif border=0 alt=NewYork width=30 height=18> "Life on Earth is expensive, but at least it includes a free trip around the Sun."

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

    Re: How do I get a form to display files in a director (MS Access 2000)

    FileSearch is available in all Office applications, including Access. I have Access 2002, and it is available "out of the box" there. Perhaps you must set a reference to the Microsoft Office 9.0 Object Library in Access 2000 to make it work (in Tools | References...), but that is just a wild guess. Perhaps somebody wh uses Access 2000 can react. Your code contains an error, though. For i = 1 to fs.FileName is not valid, since FileName is a string, not a number. Instead, use

    For i = 1 To .FoundFiles.Count

  3. #3
    3 Star Lounger
    Join Date
    Dec 2001
    Location
    Schenectady, New York, USA
    Posts
    273
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How do I get a form to display files in a director (MS Access 2000)

    Thanks Hans,

    I closed the database, reopened it and was able to move the Access 9.0 Objects below the Ofice (.0 Objects . All is working now.

    Don <img src=/S/bravo.gif border=0 alt=bravo width=16 height=30>
    Don
    <img src=/S/flags/USA.gif border=0 alt=USA width=30 height=18> <img src=/S/flags/NewYork.gif border=0 alt=NewYork width=30 height=18> "Life on Earth is expensive, but at least it includes a free trip around the Sun."

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

    Re: How do I get a form to display files in a director (MS Access 2000)

    I've been having problems with FileSearch on a couple of machines. The code doesn't error, but FoundFiles always returns 0 even though someone else can use the exact same code on their machine and get the correct results. I've seen it on both A2k and AXP and on WinXP and Win2k. <img src=/S/shrug.gif border=0 alt=shrug width=39 height=15> It must be ME!! <img src=/S/hairout.gif border=0 alt=hairout width=31 height=23>
    Charlotte

  5. #5
    Lounger
    Join Date
    Apr 2001
    Location
    Khon Kaen, Thailand
    Posts
    43
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How do I get a form to display files in a director (MS Access 2000)

    It happens to me as well. I use Dir() or Script Runtime instead.

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

    Re: How do I get a form to display files in a director (MS Access 2000)

    But have you found a reason?
    Charlotte

Posting Permissions

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