Solved

Browse for Folder

Posted on 2001-07-27
11
158 Views
Last Modified: 2010-05-02
hi,
i am making a program that needs to browse for folders, and i don't know how to do it, i think many of you can.
please somebody help me.

regards
0
Comment
Question by:samir_tartir
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +1
11 Comments
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 50 total points
ID: 6327436
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 6327569
Did you try the standard DirListBox in the toolbox (looks like a yellow folder)?
0
 

Author Comment

by:samir_tartir
ID: 6327600
i almost accepted the answer, but, the program you pointed to me is far to complex (at least for me), what i need to do is this:
press a button (which will display the folder list (which is the same one that is displayed in your program)) and then store the path the user selects.

tell me how, and the points are yours :)

thanks very much
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 22

Expert Comment

by:rspahitz
ID: 6327722
Add a DirListBox to the form along with this code:

Private Sub Dir1_Change()
  msgbox Dir1.List(Dir1.ListIndex)
End Sub

No button necessary; replace msgbox with wherever you want the path stored.

Note that this only works on the current drive.  If you want to allow the user to change drive, add a DriveListBox also.  Also note that this only supports mapped drives, not network drives.
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 6327731
Place these controls on a form:
1 listbox
1 commandbutton
1 drivelistbox
1 dirlistbox

Copy this code:
Private Sub Command1_Click()
    List1.AddItem Dir1.Path
End Sub


Now run.
0
 
LVL 2

Expert Comment

by:harnal
ID: 6327753
Do you need to search for a specific folder or list a group of folders so you can select one?  This sounds very simple, I just need a little more info from you about what you are trying to do.
0
 

Author Comment

by:samir_tartir
ID: 6327822
again this is my situation (simplified):
1. i have a form with a button (browse), and a text item (selected path).
2. if i press browse, i need the "browse for folder" to be displayed, so, i can go to the folder i need.
3. when i press ok to the folders window, i need to retrieve the path into the selected path field.
4. note: the browse for folder window can be found when you browse for a certain folder when you are using the windows search.

i hope i was clear this time!
0
 
LVL 2

Expert Comment

by:harnal
ID: 6327845
O.k. go to the project menu, and select components, then select the Microsoft common dialog control, this will provide the functionality you are looking for.
0
 

Author Comment

by:samir_tartir
ID: 6327846
'this is a simplified form of the code emoreau proposed:
Private Sub Command1_Click()
  Dim BI As BROWSEINFO
  Dim pIdl As Long
  Dim sPath As String
  Dim IDL As ITEMIDLIST
  With BI
    .hOwner = Me.hWnd
    If SHGetSpecialFolderLocation(ByVal Me.hWnd, ByVal 0, IDL) = NOERROR Then
      .pidlRoot = IDL.mkid.cb
    End If
    .pszDisplayName = String$(260, 0)
    .lpszTitle = "Browsing is limited to: Default Browse"
    .ulFlags = 1
  End With
  pIdl = SHBrowseForFolder(BI)

  ' If the dialog was cancelled...
  If pIdl = 0 Then Exit Sub
 
  sPath = String$(MAX_PATH, 0)
  SHGetPathFromIDList ByVal pIdl, ByVal sPath
 
  CoTaskMemFree pIdl
 
  MsgBox "This is your path: " + Left(sPath, InStr(sPath, vbNullChar) - 1)
End Sub


of course you need to take the needed subprograms from the attached modules.

emoreau, thanks a lot, it helped.
0
 
LVL 2

Expert Comment

by:harnal
ID: 6327853
Sorry i hit the wrong button, Please Reject this proposed answer so it will reopen the question.
0
 

Author Comment

by:samir_tartir
ID: 6327863
'this is a simplified form of the code emoreau proposed:
Private Sub Command1_Click()
  Dim BI As BROWSEINFO
  Dim pIdl As Long
  Dim sPath As String
  Dim IDL As ITEMIDLIST
  With BI
    .hOwner = Me.hWnd
    If SHGetSpecialFolderLocation(ByVal Me.hWnd, ByVal 0, IDL) = NOERROR Then
      .pidlRoot = IDL.mkid.cb
    End If
    .pszDisplayName = String$(260, 0)
    .lpszTitle = "Browsing is limited to: Default Browse"
    .ulFlags = 1
  End With
  pIdl = SHBrowseForFolder(BI)

  ' If the dialog was cancelled...
  If pIdl = 0 Then Exit Sub
 
  sPath = String$(MAX_PATH, 0)
  SHGetPathFromIDList ByVal pIdl, ByVal sPath
 
  CoTaskMemFree pIdl
 
  MsgBox "This is your path: " + Left(sPath, InStr(sPath, vbNullChar) - 1)
End Sub


of course you need to take the needed subprograms from the attached modules.

emoreau, thanks a lot, it helped.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

739 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