Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2003
    Location
    Cleveland USA
    Posts
    184

    Angry Unanswered: Why oh why isn't this working right?

    I have a popup form that gives the users a list of file names to choose from.

    The popup form looks in a folder and lists all the files in a listbox. The user selects a file name, clicks "OK", and the file name is then stored in a text box on the data entry form. The popup is then closed. This part works OK. HOWEVER, if I add a file to the folder, the listbox doesn't refresh next time I open it. In fact, I have to exit the database, come back in and then see the new files listed in the listbox.

    Here is the code for retrieving file names. It is executed when the form opens:

    Private Sub GetFiles()
    Dim i As Integer

    Dim fs As Object

    Set fs = Application.FileSearch

    With fs 'Check the \Letters folder to get a listing of available files
    .LookIn = CurrentProject.Path & "\Letters"

    If .Execute(, , AlwaysAccurate:=True) > 0 Then
    'If there are files available, then...

    For i = 1 To .FoundFiles.Count
    Me.lstFileNames.AddItem (.FoundFiles(i))
    Next i
    Else
    MsgBox "no files available"

    End If
    End With

    End Sub

  2. #2
    Join Date
    Jun 2004
    Location
    Terrapin Nation
    Posts
    205
    Set fs = Application.FileSearch










    I think that is where you problem is. Try using Set FS = GetObject(txtWithPAth).


    That may not quite do it but check out the GetObject function.

  3. #3
    Join Date
    Feb 2004
    Location
    Chicago, IL
    Posts
    1,312
    I have had some weird problems with FileSearch that made me stop using it. I would recommend using Dir() for what you are trying to do. Equivalent code would be:

    Code:
    Private Sub GetFiles()
    Dim strFilename as string
    dim intFiles as Integer
    
    With fs 'Check the \Letters folder to get a listing of available files
    strFilename = Dir(CurrentProject.Path & "\Letters\*.*")
    
    intFiles =0
    
    While strFilename<>""
    
    Me.lstFileNames.AddItem strFilename
    intFiles = intFiles+1
    strFilename=Dir()
    
    Wend
    
    
    if intFiles=0 then MsgBox "no files available"
    
    End If
    End With
    
    End Sub
    The Dir(path) starts looking in the folder named in path and then each subsequent call to Dir() with no path gets the next file in that folder. It's a little wierd, but I have never had any problems with it.

Posting Permissions

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