Get Directory Name : Common Dialogue Control

V

Venugopal Vemuri

Hi,
I am using a Common Dialogue Control on a form. I have
a command button on the form. On click of the command
button the Common Dialogue box is shown to the user. The
requirement is the user would browse and select a
directory say C:\test. The selected directory name needs
to be shown on a label control on the form. I would
require code to achieve this functionality. An early
reply would be appreciated.
Regards,
Venugopal
 
A

Andrew Backer

I use this bit of code to return the folder name from the folder
browser. I have not a darn clue where I first spotted it, or what
parts of it I wrote myself. It's just a basic API call with a little
bit of a wrapper function. I would suppose www.mvps.org was the
orginal spot, if anywhere.

-- start code ------------------

Public Const BIF_RETURNONLYFSDIRS = &H1
Public Type API_BROWSEINFO
hOwner As Long
pidlRoot As Long
pszDisplayName As String
lpszTitle As String
ulFlags As Long
lpfn As Long
lparam As Long
iImage As Long
End Type

Private Declare Function API_BrowseFolderName Lib "shell32.dll" Alias
_
"SHBrowseForFolderA" (lpBrowseInfo As API_BROWSEINFO) _
As Long

Public Function BrowseFolder(sDialogTitle As String) As String

Dim x As Long, bi As API_BROWSEINFO, dwIList As Long
Dim szPath As String, wPos As Long
Dim sOut As String

With bi
.hOwner = hWndAccessApp
.lpszTitle = sDialogTitle
.ulFlags = BIF_RETURNONLYFSDIRS
End With

dwIList = API_BrowseFolderName(bi)
szPath = Space$(512)
x = API_GetPathFromIDList(ByVal dwIList, ByVal szPath)

If x Then
wPos = InStr(szPath, Chr(0))
sOut = CStr(Left(szPath, wPos - 1))
BrowseFolder = sOut
Else
BrowseFolder = ""
End If

End Function
-- end code --------------------------

Hi,
I am using a Common Dialogue Control on a form. I have
a command button on the form. On click of the command
button the Common Dialogue box is shown to the user. The
requirement is the user would browse and select a
directory say C:\test. The selected directory name needs
to be shown on a label control on the form. I would
require code to achieve this functionality. An early
reply would be appreciated.
Regards,
Venugopal

..--------------------------------------
| Andrew Backer
| backer_a @ h0tmai1 dot com
`--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top