The common dialog is a "Browse For File" control, not a "Browse For Folder" control. To folder browse, use this:VB Code:
Public Function BrowseForFolder(hWndOwner As Long, sPrompt As String) As String Dim iNull As Integer Dim lpIDList As Long Dim lResult As Long Dim sPath As String Dim udtBI As BrowseInfo With udtBI .hWndOwner = hWndOwner .lpszTitle = lstrcat(sPrompt, "") .ulFlags = BIF_RETURNONLYFSDIRS .lpfnCallback = PassBackAddress(AddressOf BrowseCallBackProc) End With lpIDList = SHBrowseForFolder(udtBI) If lpIDList Then sPath = String$(MAX_PATH, 0) lResult = SHGetPathFromIDList(lpIDList, sPath) Call CoTaskMemFree(lpIDList) iNull = InStr(sPath, vbNullChar) If iNull Then sPath = Left$(sPath, iNull - 1) End If End If BrowseForFolder = sPath End Function Private Sub cmdBrowse_Click() Dim sDocFolderPath As String sDocFolderPath = BrowseForFolder(Form1.hWnd, "Select A Folder") If sDocFolderPath <> "" Then 'store selected folder in textbox Text1.Text = sDocFolderPath End If End Sub




Reply With Quote