Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Microsoft: Access Modules (VBA Coding) FAQ

Opening Files

Selecting a Folder (not a file) by BigTeeJay
Posted: 16 Aug 02

I remember reading somewhere that this isnt possible, which I found hard to believe (especially since I am sure everyone has seen it done already at one time or another). The below code was supposed to be for VB (but works just as well for VBA)

The below code was found at...

====== Begin Code Block ========
Option Explicit

Private Type BrowseInfo
    hWndOwner As Long
    pidlRoot As Long
    sDisplayName As String
    sTitle As String
    ulFlags As Long
    lpfn As Long
    lParam As Long
    iImage As Long
End Type

Private Declare Function
SHBrowseForFolder Lib "Shell32.dll" (bBrowse As BrowseInfo) As Long
Private Declare Function
SHGetPathFromIDList Lib "Shell32.dll" (ByVal lItem As Long, ByVal sDir As String) As Long

' Let the user browse for a directory. Return the
' selected directory. Return an empty string if
' the user cancels.

Private Function BrowseForDirectory() As String
Dim browse_info As BrowseInfo
Dim item As Long
Dim dir_name As String

   'modified for MS Access/VBA
   With browse_info
       .hWndOwner = Application.hWndAccessApp
       .pidlRoot = 0
       .sDisplayName = Space$(260)
       .sTitle = "Select Directory"
       .ulFlags = 1 ' Return directory name.
       .lpfn = 0
       .lParam = 0
       .iImage = 0
   End With

   item = SHBrowseForFolder(browse_info)
   If item Then
       dir_name = Space$(260)
       If SHGetPathFromIDList(item, dir_name) Then
           BrowseForDirectory = Left(dir_name, _
                                InStr(dir_name, Chr$(0)) - 1)
           BrowseForDirectory = ""
       End If
   End If
End Function

Private Sub
    MsgBox BrowseForDirectory
End Sub

======= End Code Block ========

You can download a sample project which utilizes this from their website. It's not easy to find, so here is the link...

spam__me (at) excite (dot) com

Back to Microsoft: Access Modules (VBA Coding) FAQ Index
Back to Microsoft: Access Modules (VBA Coding) Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close