Solved

Browse for Folder

Posted on 2001-07-27
11
153 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 69

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
 
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 69

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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Excel Spreadsheet - Send email if certain value is selected. 14 79
z = x + y – 1 6 57
Window placement 17 65
Using "ScreenUpdating" 6 45
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
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…
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…

757 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now