Results 1 to 3 of 3
  1. #1
    Star Lounger
    Join Date
    Jun 2004
    Location
    Lambertville, New Jersey, USA
    Posts
    82
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have a report generation form that allows the user to i/p selection criteria and run various reports. Some of the reports are saved to a default folder.

    I want to provide the user with the ability to "browse" and select the folder to save the files to. I've been all through my many reference books but can't find a starting point. Any guidence would be appreciated.

    I'm using Access 2002/2003 for this one.

    Thanks,
    Lance

  2. #2
    5 Star Lounger AndrewKKWalker's Avatar
    Join Date
    Apr 2001
    Location
    Cambridge, UK
    Posts
    1,020
    Thanks
    0
    Thanked 3 Times in 3 Posts
    If you are using Access 2003, you could try using the Microsoft Common Dialogue Control.
    You can place it on a form and call it with a button.

    CommonDialogue1.ShowOpen for example

    It does not actually open a file, but returns the selected file name with the

    strFile=CommonDialogue1.FileName property

    If you then use InstrRev with Left, you would be able to find the Last \
    and thus get the Folder Name selected.

    As far as I can remember the Common Dialogue will not work in Access 2000.

    I am willing to be corrected on that.
    Andrew

  3. #3
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    Brisbane, Queensland, Australia
    Posts
    387
    Thanks
    0
    Thanked 1 Time in 1 Post
    Stick the following in a module -

    Code:
    Option Compare Database
    Option Explicit
    'This module contains all the declarations to use the Windows 95 Shell API to use the browse for folders
    'dialog box. To use the browse for folders dialog box, please call the BrowseForFolders function using the
    'syntax: stringFolderPath=BrowseForFolders(Hwnd,TitleOfDialog)
    Public 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 Const BIF_RETURNONLYFSDIRS = 1
    Public Const MAX_PATH = 260
    Public Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal hMem As Long)
    Public Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" (ByVal lpString1 As String, ByVal lpString2 As String) As Long
    Public Declare Function SHBrowseForFolder Lib "shell32" (lpBI As BROWSEINFO) As Long
    Public Declare Function SHGetPathFromIDList Lib "shell32" (ByVal pidList As Long, ByVal lpBuffer As String) As Long
    
    Public Function BrowseForFolder(Optional hwndOwner As Long = 0, Optional sPrompt As String = "Find Directory") As String
    Dim iNull As Integer
    Dim lpIDList As Long
    Dim lResult As Long
    Dim sPath As String
    Dim udtBI As BROWSEINFO
    'initialise variables
    With udtBI
       .hwndOwner = hwndOwner
       .lpszTitle = lstrcat(sPrompt, "")
       .ulFlags = BIF_RETURNONLYFSDIRS
    End With
    'Call the browse for folder API
    lpIDList = SHBrowseForFolder(udtBI)
    'get the resulting string path
    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
    'If cancel was pressed, sPath = ""
    BrowseForFolder = sPath
    
    End Function
    then use the BrowseForFolder function in your code (note the arguments are optional and I never use them). eg -

    strFolder = BrowseForFolder()

    this will open the folder browser and return the path to the folder the user selects.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •