How to browser the folder structure in Access

  • Thread starter Thread starter Mei Qin
  • Start date Start date
M

Mei Qin

Hello,

In my form, I need to ask the user to put in the file path
in a text box, so I can export my reports to that
location. But the user wants to browser the folder
structure on their PC and then click on it as a selected
path. I know we can do it in Visual Basic. How should I do
it in Access?

Thanks for any help!

Mei
 
In this example, I have to choose a file to open or save.
But I only need the path. What can I do, if there is no
file in the folder?

Thanks!

Mei
 
All Microsoft navigation windows require a file for "selecting" even if
you're just going to get the path.

If you won't have that option, then you'll need a customized method to get
the path, which won't be via any built-in Microsoft method.
 
See:
http://www.mvps.org/access/api/api0002.htm
Author(s)
Terry Kreft


(Q) Ok, I know how to use the GetOpenFileName api, but I want to just
retrieve the Directory name. How do I call the Browse for Folder window
from code?

(A) Paste the following code in a new module. Save the module with any
name. Use the following example as an illustration on how to call the
function.

Dim strFolderName as string

strFolderName = BrowseFolder("What Folder you want to select?")

Stephen Lebans has added functionality to open the browse folder at a
specific place.

'************** Code Start **************
'This code was originally written by Terry Kreft.
'It is not to be altered or distributed,
'except as part of an application.
'You are free to use it in any application,
'provided the copyright notice is left unchanged.
'
'Code courtesy of
'Terry Kreft

Private Type 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 SHGetPathFromIDList Lib "shell32.dll" Alias _
"SHGetPathFromIDListA" (ByVal pidl As Long, _
ByVal pszPath As String) As Long

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

Private Const BIF_RETURNONLYFSDIRS = &H1
Public Function BrowseFolder(szDialogTitle As String) As String
Dim X As Long, bi As BROWSEINFO, dwIList As Long
Dim szPath As String, wPos As Integer

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

dwIList = SHBrowseForFolder(bi)
szPath = Space$(512)
X = SHGetPathFromIDList(ByVal dwIList, ByVal szPath)

If X Then
wPos = InStr(szPath, Chr(0))
BrowseFolder = Left$(szPath, wPos - 1)
Else
BrowseFolder = vbNullString
End If
End Function
'*********** Code End *****************



--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
 
It works. Thanks!
-----Original Message-----
See:
http://www.mvps.org/access/api/api0002.htm
Author(s)
Terry Kreft


(Q) Ok, I know how to use the GetOpenFileName api, but I want to just
retrieve the Directory name. How do I call the Browse for Folder window
from code?

(A) Paste the following code in a new module. Save the module with any
name. Use the following example as an illustration on how to call the
function.

Dim strFolderName as string

strFolderName = BrowseFolder("What Folder you want to select?")

Stephen Lebans has added functionality to open the browse folder at a
specific place.

'************** Code Start **************
'This code was originally written by Terry Kreft.
'It is not to be altered or distributed,
'except as part of an application.
'You are free to use it in any application,
'provided the copyright notice is left unchanged.
'
'Code courtesy of
'Terry Kreft

Private Type 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 SHGetPathFromIDList Lib "shell32.dll" Alias _
"SHGetPathFromIDListA" (ByVal pidl As Long, _
ByVal pszPath As String) As Long

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

Private Const BIF_RETURNONLYFSDIRS = &H1
Public Function BrowseFolder(szDialogTitle As String) As String
Dim X As Long, bi As BROWSEINFO, dwIList As Long
Dim szPath As String, wPos As Integer

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

dwIList = SHBrowseForFolder(bi)
szPath = Space$(512)
X = SHGetPathFromIDList(ByVal dwIList, ByVal szPath)

If X Then
wPos = InStr(szPath, Chr(0))
BrowseFolder = Left$(szPath, wPos - 1)
Else
BrowseFolder = vbNullString
End If
End Function
'*********** Code End *****************



--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.




.
 
Back
Top