Avatar of khaledc
khaledc
 asked on

Directory Selection Control

Dear All,

I am using VB6 and usually to I use the MS Common Dialog control to save and open file. However, I only need to locate a directory and I would like to know if the MS Common Dialog control can still be used with some special settings to the its flags property (or any other property).

Note that I have a third party control that does the job but I would like to keep my controls native to VB.

Your help is appreciated.

Regards.
Visual Basic Classic

Avatar of undefined
Last Comment
khaledc

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
cquinn

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
vinnyd79


Private Sub Command1_Click()
Dim wShell As Object, myFolder As Object
Set wShell = CreateObject("Shell.Application")
Set myFolder = wShell.BrowseForFolder(0, "My Dialog Title", &H1)
MsgBox myFolder.Items.Item.Path

End Sub
bmiller264

The easiest thing to do is create your own form.

Add a DriveListBox... and a DirListBox (standard VB6 Controls).  The click on the DriveListBox refereshes the DirListBox and then a "Save" button would return the selected directory path.

Example:   (you can make the form look however you want...)
DriveListBox (named Drive1)
DirListBox (named Dir1)
CommandButton (named cmdOK)

Code on the form:
Public lcPath
Public Event PathSelected(PathName As String)

Private Sub cmdOK_Click()
   
    If UCase(Left$(Dir1.path, 1)) <> UCase(Left$(Drive1.Drive, 1)) Then
        lcPath = Drive1.Drive & "\"
    Else
        lcPath = Dir1.path
    End If
    RaiseEvent PathSelected(CStr(lcPath))
    Unload Me
   
End Sub

Private Sub Drive1_Change()

    Dir1.path = Drive1.Drive
    Dir1.Refresh

End Sub

Private Sub Form_Load()

    On Error Resume Next
   
    If lcPath = "" Then
        Drive1.Drive = App.path
        Dir1.path = App.path
    Else
        Drive1.Drive = lcPath
        Dir1.path = lcPath
    End If

End Sub



khaledc

ASKER
cquinn,

Is the BrowseForFolder a native Windows API?

Cheers.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
khaledc

ASKER
It worked well. Thanks