Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2002
    Posts
    72

    Unanswered: Directory Listing - Is this possible to do?

    Don't know if this is too complex for Access but what I want to do is set a combo box to list all *.doc files in a specific directory on my hard drive. When one is selcted the appropriate file opens.

    Thanks

  2. #2
    Join Date
    Nov 2002
    Posts
    150

    Re: Directory Listing - Is this possible to do?

    Originally posted by Spanner
    Don't know if this is too complex for Access but what I want to do is set a combo box to list all *.doc files in a specific directory on my hard drive. When one is selcted the appropriate file opens.

    Thanks
    Implement where needed:

    Private Sub findfiles()
    Dim MyPath As String
    Dim MyName As String
    Dim MyFiles As String
    MyPath = "c:\"
    MyName = Dir(MyPath & "*.txt")
    MyFiles = ""
    Do While MyName <> ""
    MyFiles = MyFiles & MyName & ";"
    MyName = Dir
    Loop
    Me.Combo1.RowSource = MyFiles
    End Sub

  3. #3
    Join Date
    Nov 2002
    Location
    San Francisco
    Posts
    251
    You can use FILESEARCH..... it allows you to sort it....

    add reference to Microsoft Office Library and then you can use

    ? GetDocumentsFromDirectory ("C:\My Documents")


    Public Function GetDocumentsFromDirectory(InputPath As String) As String
    Dim fs As FileSearch
    Dim i As Integer

    GetDocumentsFromDirectory = ""
    Set fs = Application.FileSearch
    With fs
    .LookIn = InputPath
    .FileName = "*.doc"
    If .Execute(SortBy:=msoSortbyFileName, _
    SortOrder:=msoSortOrderAscending) > 0 Then
    For i = 1 To .FoundFiles.Count
    GetDocumentsFromDirectory = GetDocumentsFromDirectory & ";" & .FoundFiles(i)
    Next i
    GetDocumentsFromDirectory = Mid(GetDocumentsFromDirectory, 2)
    End If
    End With
    End Function

  4. #4
    Join Date
    Jun 2002
    Posts
    72
    Originally posted by playernovis
    You can use FILESEARCH..... it allows you to sort it....

    add reference to Microsoft Office Library and then you can use

    ? GetDocumentsFromDirectory ("C:\My Documents")


    Public Function GetDocumentsFromDirectory(InputPath As String) As String
    Dim fs As FileSearch
    Dim i As Integer

    GetDocumentsFromDirectory = ""
    Set fs = Application.FileSearch
    With fs
    .LookIn = InputPath
    .FileName = "*.doc"
    If .Execute(SortBy:=msoSortbyFileName, _
    SortOrder:=msoSortOrderAscending) > 0 Then
    For i = 1 To .FoundFiles.Count
    GetDocumentsFromDirectory = GetDocumentsFromDirectory & ";" & .FoundFiles(i)
    Next i
    GetDocumentsFromDirectory = Mid(GetDocumentsFromDirectory, 2)
    End If
    End With
    End Function

  5. #5
    Join Date
    Jun 2002
    Posts
    72

    Thanks

    My next question was going to be how do I sort the names - but thanks to playernovis you anticipated my question. Thanks to both FirstAndGoal4 and playernovis, it worked great!

Posting Permissions

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