?
Solved

Browse for Folder

Posted on 2001-07-27
11
Medium Priority
?
163 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 200 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
Independent Software Vendors: 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month16 days, 23 hours left to enroll

864 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