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

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
Who is Participating?
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
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.


DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
"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

Jeffrey CoachmanMIS LiasonCommented:
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...

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

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

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.
Jeffrey CoachmanMIS LiasonCommented:

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?

DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
"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.

shambaladAuthor Commented:
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)

shambaladAuthor Commented:
Thanks again,
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
Appreciate the feedback Todd ... good info.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.