Looking for dialog to Select Folder that allows viewing files in the folder

Posted on 2011-10-13
Last Modified: 2012-05-12

Hello -
I am working on an app (2007/accdb) where the user is required to select a folder containing text files to be processed. Currently I am using that old standby BrowseFolder (SHBrowseForFolder) function. It works but lacks the level of functionality I would really like to have.

 Current BrowseFolder dialog
Basically, I want to be able to view the files that are in the folder. The process that is kicked off is fairly involved, and I would like for the user to be able to actually see the files that are in the folder as they select the folder.
What I would like to have is a modified file open/save dialog. These, too, have been around for a while. I found a nice version of the dialog provided by Capicorn1 in the following post:

Here is a snapshot of what the file dialog looks like, along with what I'd like to change on it. Can I accomplish using keywords?

 Preferred dialog
Is there maybe some other way to accomplish what I'm trying to do here?
I am including an upload of the the database, FileBrowser.accdb. This is simply a copy of Capicorn1's original FileBrowser.mdb converted to Access2007
Question by:shambalad
    LVL 75

    Accepted Solution

    Play around with this ... which I believe is the new start of the art way to do this.  I think you do need the Reference to the Scripting Runtime (pretty sure) ... image 1.

    Public Function msoFileFolderBrowse() As Boolean

        With FileDialog(msoFileDialogFilePicker)
            If .Show Then Debug.Print .SelectedItems(1)
        End With
    '    With FileDialog(msoFileDialogFolderPicker)
    '        If .Show Then Debug.Print .SelectedItems(1)
    '    End With

    End Function

    So, for example ... if you call msoFileFolderBrowse() from the VBA Immediate window ... it pops up the Common dialog.  I haven't played with it a lot yet, but check it out.


    LVL 75

    Expert Comment

    by:DatabaseMX (Joe Anderson - Access MVP)
    "This is simply a copy of Capicorn1's original FileBrowser.mdb converted to Access2007"
    btw ... that is nothing more than the long standing Ken Getz (et al) code found in many places, and originating in the Access Developer's Handbook by the same people.

    '***************** Code Start **************
    'This code was originally written by Ken Getz.
    'It is not to be altered or distributed,
    'except as part of an application.
    'You are free to use it in any application,
    'provided the copyright notice is left unchanged.
    ' Code courtesy of:
    '   Microsoft Access 95 How-To
    ' Ken Getz and Paul Litwin
    ' Waite Group Press, 1996

    LVL 74

    Expert Comment

    by:Jeffrey Coachman
    Oddly enough, this is only something I have ever seen in specifics apps.

    Usually this is done by first selecting the folder, (via the Browse Folder code), then displaying the files form a standard file dialog box (via what the other Experts posted above)

    Even the MS dialog boxes force you to only navigate folders via the file name dropdown, if your folder is not one of the defaults...

    I have never see a full folder navigation "Tree View" on one side, and files listed on the other, in one dialog box...

    You can investigate one of the FMS controls:

    ...and email them to ask if what you need is possible...

    LVL 26

    Expert Comment

    I use the FileSystemObject and FileDialog a lot
    The default is Select but the right-click give you a choice for Open amongst others, which you can then use to look at the file, before double-clicking to select it.

    Here's a sample.
    Click the button
    Right-click anything in the File Dialog box to see what I mean
    LVL 26

    Assisted Solution


    You want to be able to see and preview the files, but actually select the folder they are in.
    The sample gives you the FilePicker variant, which you need to be actually able to see the files, and use the right-click trick on.
    The FolderPicker variant doesn't give you that

    Notice that the msgbox at the end returns the full path?
    It's pretty damn easy to strip the filename off that string and just use the path for what you really want.
    And it's easy enough to educate the users to browse to a folder and pick any file out of it to set the process off.
    LVL 74

    Expert Comment

    by:Jeffrey Coachman

    In light of what Nick posted, I guess you could say that if you want something "Easy" to implement you could use the standard Dialog box code:
    Then simply let users navigate the folders via the file name drop down.

    If you need something "Slicker", (read: Custom) then quite a bit of extra work may be required...

    In a larger sense, most developers will not allow users full access to every folder.
    Typically a specific folder will be designated, (this will be the default folder when the dialog box opens)
    Then beneath this Main folder, sub folders will exist; where files can be selected from (or saved to.)

    Are you saying that the location of these textfiles could be virtually *anywhere* the user can navigate to, ...and the location of these files cannot be more tightly controlled?

    LVL 75

    Expert Comment

    by:DatabaseMX (Joe Anderson - Access MVP)
    "if you want something "Easy" to implement you could use the standard Dialog box code:"

    But I think the FileDialog(msoFileDialogFilePicker) is a LOT less code.

    LVL 7

    Author Comment

    Thank you all for the input. This is one of those final touches on a six month project that is going live at the end of the month and yesterday was another marathon session, so I apologize for not getting back to this sooner.
    As some things come around in circles, so I find myself again using the FileDialog object. For some reason, I seem to recall that there was some limitation with one of the msoFileDialogTypes in Access 2003, wherein the 'Getz' version offered a little more flexibility, that turned me away from the FileDialog object about 6-7 years ago. Anyway, I'm finding that it seems to be working well enough for me today. I certainly have to agree with you, mx, the FileDialog is a whole lot less code. Adopting it allows me to delete a bas module (which I use for the 'Getz' version) from my project; I always like that.
    First, I should note that a factor in my decision to take the approach I have is that my target user base is fairly sophisticated, especially with Microsoft Office products. What I am doing is offering the user a choice of using either the msoFileDialogFilePicker or the msoFileDialogFolderPicker by means of a checkbox on the form. The initial default is the msoFileDialogFolderPicker. Much as Nick67 suggests above, if using the msoFileDialogFilePicker window, I instruct the user in the title prompt to select any file in the folder to continue. I then strip out the folder path in the code. (Actually, Nick67, I'd already taken this course of action by the time you posted your suggestion, but I'm going to allocate some points to you anyway for being on the right track).
    So it ends up looking something like this:

    If blnUseFilePicker then
       intFileDialogType = msoFileDialogFilePicker
       intFileDialogType = msoFileDialogFolderPicker
    end if

    With FileDialog(intFileDialogType )
       If .Show Then strSelected = .SelectedItems(1)
    End With
    If blnUseFilePicker then strSelected = GetFolderFromPath(strSelected)

    LVL 7

    Author Closing Comment

    Thanks again,
    LVL 75

    Expert Comment

    by:DatabaseMX (Joe Anderson - Access MVP)
    Appreciate the feedback Todd ... good info.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
    Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
    Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
    Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now