Results 1 to 6 of 6
  1. #1
    Middlemarch is offline Competent Performer
    Windows 10 Access 2019
    Join Date
    Mar 2015
    Posts
    340

    Browse for Folder

    Hi, Using the following to select a folder
    Code:
    Option Explicit
    
    
    Private Const BIF_RETURNONLYFSDIRS = 1
    Private Const BIF_DONTGOBELOWDOMAIN = 2
    Private Const MAX_PATH = 260
    
    
    Private Declare Function SHBrowseForFolder Lib "shell32" _
                                      (lpbi As BROWSEINFO) As Long
    
    
    Private Declare Function SHGetPathFromIDList Lib "shell32" _
                                      (ByVal pidList As Long, _
                                      ByVal lpBuffer As String) As Long
    
    
    Private Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" _
                                      (ByVal lpString1 As String, ByVal _
                                      lpString2 As String) As Long
    
    
    Private Declare Function GetActiveWindow Lib "user32" () As Long
    
    
    Private Type BROWSEINFO
       hwndOwner      As Long
       pidlRoot       As Long
       pszDisplayName As Long
       lpszTitle      As Long
       ulFlags        As Long
       lpfnCallback   As Long
       lParam         As Long
       iImage         As Long
    End Type
    
    
    Public Function BrowseFolder$(Optional Title$ = "")
    'Opens a Treeview control that displays the directories in a computer
    
    
       Dim lpIDList As Long
       Dim sBuffer As String
       Dim szTitle As String
       Dim tBrowseInfo As BROWSEINFO
       
       With tBrowseInfo
        .
          .hwndOwner = GetActiveWindow
          .lpszTitle = lstrcat(Title$, "")
          .ulFlags = BIF_RETURNONLYFSDIRS + BIF_DONTGOBELOWDOMAIN
       End With
    
    
       lpIDList = SHBrowseForFolder(tBrowseInfo)
    
    
       If (lpIDList) Then
          sBuffer = Space(MAX_PATH)
          SHGetPathFromIDList lpIDList, sBuffer
          sBuffer = Left(sBuffer, InStr(sBuffer, vbNullChar) - 1)
          BrowseFolder$ = sBuffer
       End If
    End Function
    
    
    Sub test()
    MsgBox BrowseFolder$()
    End Sub
    What can I do to pass a default folder it will open at ?

    Thanks.

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,861
    Go back to where you got the code.
    Must be some details about it?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    Middlemarch is offline Competent Performer
    Windows 10 Access 2019
    Join Date
    Mar 2015
    Posts
    340
    Its very old, doubt I'd find anything. Maybe there's something else being used now ? I'm sure I've seen such a thing but can't find it.

  4. #4
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,101
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  5. #5
    Middlemarch is offline Competent Performer
    Windows 10 Access 2019
    Join Date
    Mar 2015
    Posts
    340
    Many thanks @Gicu. One at stackoverflow gave me just what I wanted.

  6. #6
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,101

    Glad to help, good luck with your project!
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Browse to Folder feature
    By Paul H in forum Forms
    Replies: 1
    Last Post: 05-17-2021, 09:48 AM
  2. Replies: 8
    Last Post: 09-15-2019, 07:37 AM
  3. Browse and Open Folder Based on Matching Form Field
    By Tomfernandez1 in forum Access
    Replies: 11
    Last Post: 02-26-2013, 01:04 PM
  4. Browse For Folder Example
    By pkstormy in forum Code Repository
    Replies: 6
    Last Post: 01-08-2012, 04:13 PM
  5. Need an ActiveX control for folder browse
    By dbodell in forum Programming
    Replies: 4
    Last Post: 08-24-2011, 12:56 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums