views:

2610

answers:

6

How to put a File path control in VBA front panel? I want the user to be able to select the browse button and select the file path rather than putting up dialog boxes all over the place. I need the user to select three or more file paths.

+1  A: 

Do you mean VBA for Microsoft Office or just general VBA?

In Office, Application.FileDialog(msoFileDialogOpen).

Otherwise, look at the Win32 API function SHBrowseForFolder (in shell32.dll). You can import it for use into VBA using the Declare Function keywords.

fwzgekg
I do not want to use a file dialog. I want a File Path control (like a string control). A text box with a browse button - is there anyother name for it?
Manoj
+1  A: 

There is not direct VBA function for that. You can decide to combine a form (Access form, or a generic microsoft form) with 2 controls: (1) text box (2) browse button (which will finally use the fileDialog command or a windows API).

Philippe Grondier
+1  A: 

Perhaps the browse for folder API from the Microsoft MVPs site would suit:

http://www.mvps.org/access/api/api0002.htm

It uses SHBrowseForFolder mentioned by fwzgekg, and does not return a file dialog, it returns a browsable list of folders.

Remou
A: 

Thanks for the answers. Will try them out.

Manoj
+1  A: 

After re-re-reading your Q, it seams you want to steer away from dialog boxes!Oh well, I was going to say

I could post the hack about using MSDIAG on VBA, that explains how you can patch your registry to enable its use under VBA, without having other MS-VB products installed... but I rather have you google that one... you can certainly understand why.

But you don't want Dialog Boxes... you want controls and buttons: Use listboxes! To populate your listbox, use the Dir command (using method additem of the listbox). Two phases for achieving that:

  • first get the Directories (and prefix a "->" or whatever prior to adding it on the listbox, so that the user understands this is not a file);
  • then get filenames (you can filter by extension with the arguments of Dir, just as you would in DOS).

Finally, under OnClick and OnDoubleClick of the listbox, you must interpret the listbox default property (Item), check for "->" and use ChDir to change directory and repopulate, or you'll have your file selected.

The write up is sooooooo much more complicated than the code... trust me.

jpinto3912
A: 

Here is what u want?

FilePath = Application.GetOpenFilename

Regards,

nghmuon