Solved

Browse for Folder

Posted on 2001-07-27
11
156 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
  • 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
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.

 
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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

838 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